VG-Electronics
VG-Electronics

Reputation: 279

Laravel Redis - artisan cache:clear - Connection refused [unix:/path/.redis/redis.sock]

 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.

Upvotes: 1

Views: 1408

Answers (3)

user2560539
user2560539

Reputation:

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),
    ]
]

Upvotes: 0

behzad babaei
behzad babaei

Reputation: 1161

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

Upvotes: 1

user9079355
user9079355

Reputation:

set REDIS_HOST=127.0.0.1 or your host address

Upvotes: 0

Related Questions