1

 I have configured Redis (using a socket) in the Laravel in my hosting server. Everything works fine (I have tested reading from cache, sessions etc.), I have one database for a cache and a second one for users sessions.
 However, when I run "php artisan cache:clear" it shows the error:
"In AbstractConnection.php line 155: Connection refused [unix:/path/.redis/redis.sock]".
This error also occures when I run any command which uses Redis, for example "php73 artisan cron:updateForeignPrices".

.env

CACHE_DRIVER=redis
SESSION_DRIVER=redis

REDIS_HOST=/path/.redis/redis.sock
REDIS_PASSWORD=null
REDIS_PORT=0
REDIS_CACHE_DB=0
REDIS_SESSION_DB=1

config/database.php

'redis' => [
    'client' => env('REDIS_CLIENT', 'predis'),
    'cluster' => true,

    'options' => [
        'cluster' => env('REDIS_CLUSTER', 'predis'),
        'prefix' => Str::slug(env('APP_NAME'), '_').'_',
        'parameters' => ['password' => env('REDIS_PASSWORD', null)],
    ],

    'default' => [
        'scheme' => 'unix',
        'path' => env('REDIS_HOST'),
        'host' => env('REDIS_HOST'),
        'password' => env('REDIS_PASSWORD'),
        'port' => env('REDIS_PORT'),
        'database' => env('REDIS_CACHE_DB', 0)
    ],

    'cache' => [
        'scheme' => 'unix',
        'path' => env('REDIS_HOST'),
        'host' => env('REDIS_HOST'),
        'password' => env('REDIS_PASSWORD'),
        'port' => env('REDIS_PORT'),
        'database' => env('REDIS_CACHE_DB', 0),
    ],

    'session' => [
        'scheme' => 'unix',
        'path' => env('REDIS_HOST'),
        'host' => env('REDIS_HOST'),
        'password' => env('REDIS_PASSWORD'),
        'port' => env('REDIS_PORT'),
        'database' => env('REDIS_SESSION_DB', 1),
    ]
]

Hosting provider's info about Redis (translated):
Socket: /path-to-my-directory/.redis/redis.sock
User and password: (none)
Port: 0
RAM: 128 MB
Instruction on WordPress Litespeed:

  1. In the „Host” field paste address from the panel, for example: /home/klient.dhosting.pl/dhtutorial/.redis/redis.sock
  2. In the „Port” field remove a default value and type "0".
  3. Leave "user" and "password" empty.

 It seems like everything works correctly in a direct use of Redis, but not via console. Anyone has an idea how to fix it?
Thanks in advance, I have searched whole Internet.

7
  • If my answer does not help you, let me know more about your issue, so that I will be able to help you. Commented Sep 29, 2020 at 22:49
  • What Laravel version are you using? Do you have predis/predis dependency installed? Commented Sep 30, 2020 at 8:27
  • Sorry for a late answer. Check out my updated question (hosting provider info section). Commented Oct 3, 2020 at 9:52
  • Laravel version is 5.8, I'm using Predis. Commented Oct 3, 2020 at 9:59
  • @SentalPL It seems like everything works correctly in a direct use of Redis, but not via console.. What console? You mean the redis-cli command line or the execution of this php artisan cache:clear? Commented Oct 4, 2020 at 12:56

3 Answers 3

1

REDIS_HOST should point to the address where the Redis server is hosted whether it's hosted on a local machine or cloud service. somethings like below:

REDIS_HOST=12.0.0.1
REDIS_PASSWORD=password
REDIS_PORT=6379
Sign up to request clarification or add additional context in comments.

1 Comment

I'm using a socket, so when I change a path like just in localhost it shows the error "No such file or directory [unix:127.0.0.1]".
0

set REDIS_HOST=127.0.0.1 or your host address

1 Comment

It's not working. Check my updated question (I added a section about configuration).
0

Try to use the following configuration.

.env

CACHE_DRIVER=redis
SESSION_DRIVER=redis

REDIS_SCHEME=unix
REDIS_PATH=/path/.redis/redis.sock

REDIS_CACHE_DB=0
REDIS_SESSION_DB=1

config.database.php

'redis' => [
    'client' => env('REDIS_CLIENT', 'predis'),
    'cluster' => true,

    'options' => [
        'cluster' => env('REDIS_CLUSTER', 'predis'),
        'prefix' => Str::slug(env('APP_NAME'), '_').'_',
        'parameters' => ['password' => null],
    ],

    'default' => [
        'scheme' => env('REDIS_SCHEME'),
        'path' => env('REDIS_PATH'),
        'database' => env('REDIS_CACHE_DB', 0)
    ],

    'cache' => [
        'scheme' => env('REDIS_SCHEME'),
        'path' => env('REDIS_PATH'),
        'database' => env('REDIS_CACHE_DB', 0),
    ],

    'session' => [
        'scheme' => env('REDIS_SCHEME'),
        'path' => env('REDIS_PATH'),
        'database' => env('REDIS_SESSION_DB', 1),
    ]
]

2 Comments

Didn't work :/ Anyway, nothing was changed there except removing 3 lines for each driver and typing "unix" scheme as the env variable.
@SentalPL try to also add HOST. Although i don't think it is needed. There is a good chance that ACL is used redis.io/topics/acl. Have you checked that no specific rules for specific users are set?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.