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:
In the „Host” field paste address from the panel, for example: /home/klient.dhosting.pl/dhtutorial/.redis/redis.sock
In the „Port” field remove a default value and type "0".
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.
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
set REDIS_HOST=127.0.0.1 or your host address
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),
]
]
Related
I faced unusual problem with my horizon and my jobs stopped working due to the error with ssl handshake time out. I restarted horizon and supervisor but the problem didn't disappear. I would be glad if someone solved this problem and can help me
my configs:
database.php
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
],
'default' => [
'scheme' => 'tls',
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '1'),
],
## Heading ##
horizon.php
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => [
env('QUEUE_NAME', 'service_royxat'),
'default',
],
'balance' => 'auto',
'processes' => 12,
'tries' => 3,
'timeout' => 60,
],
],
'local' => [
'supervisor-1' => [
'maxProcesses' => 3,
],
],
],
I've setup redis-cluster on Amazon ElastiCache for cache, using Laravel 5.5 and Predis package, I get the following error.
Predis\ClientException: No connections available in the pool in vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php:337
Trace:
Predis\ClientException: No connections available in the pool in vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php:337
Stack trace:
0 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(411):
Predis\Connection\Aggregate\RedisCluster->guessNode(153)
1 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(388):
Predis\Connection\Aggregate\RedisCluster->getConnectionBySlot(153)
2 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(550):
Predis\Connection\Aggregate\RedisCluster->getConnection(Object(Predis\Command\StringSetExpire))
3 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(593):
Predis\Connection\Aggregate\RedisCluster->retryCommandOnFailure(Object(Predis\Command\StringSetExpire),
'executeCommand')
4 vendor/predis/predis/src/Client.php(331): Predis\Connection\Aggregate\RedisCluster->executeCommand(Object(Predis\Command\StringSetExpire))
5 vendor/predis/predis/src/Client.php(314): Predis\Client->executeCommand(Object(Predis\Command\StringSetExpire))
6 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(96):
Predis\Client->__call('setex', Array)
7 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(108):
Illuminate\Redis\Connections\Connection->command('setex', Array)
8 vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php(93): Illuminate\Redis\Connections\Connection->__call('setex', Array)
9 vendor/laravel/framework/src/Illuminate/Cache/Repository.php(195): Illuminate\Cache\RedisStore->put('5rr44TBjIPEgJSx...',
'a:1:{s:6:"_flas...', 480)
10 vendor/laravel/framework/src/Illuminate/Session/CacheBasedSessionHandler.php(66):
Illuminate\Cache\Repository->put('5rr44TBjIPEgJSx...',
'a:1:{s:6:"_flas...', 480)
11 vendor/laravel/framework/src/Illuminate/Session/Store.php(128): Illuminate\Session\CacheBasedSessionHandler->write('5rr44TBjIPEgJSx...',
'a:1:{s:6:"_flas...')
12 vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(87):
Illuminate\Session\Store->save()
13 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(218):
Illuminate\Session\Middleware\StartSession->terminate(Object(Illuminate\Http\Request),
Object(Illuminate\Http\Response))
14 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(189):
Illuminate\Foundation\Http\Kernel->terminateMiddleware(Object(Illuminate\Http\Request),
Object(Illuminate\Http\Response))
15 public/index.php(58): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request),
Object(Illuminate\Http\Response))
16 {main}
Technical stack I used:
PHP7.0
Laravel5.5
OS (Debian GNU/Linux 9.6 (stretch)), Release 9.6
I tried the following configs in config/database.php:
redis=> [
'client' => 'predis',
'options' => [
'cluster' => 'redis',
],
'clusters' => [
'default' => [
[
'host' => env('REDIS_CLUSTER_HOST', 'localhost'),
'password' => env('REDIS_CLUSTER_PASSWORD', null),
'port' => env('REDIS_CLUSTER_PORT', 6379),
'database' => 0,
],
],
'cache' => [
[
'host' => env('REDIS_CLUSTER_HOST', 'localhost'),
'password' => env('REDIS_CLUSTER_PASSWORD', null),
'port' => env('REDIS_CLUSTER_PORT', 6379),
'database' => 0,
],
],
]
]
I also tried with timeout => 0|5|60 but every time I get the same error.
Any help would be highly appreciated!
This is working in in our env:
'redis' => [
'cluster' => true,
'client' => 'predis',
'options' => [
'cluster' => 'redis',
'parameters' => [
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'timeout' => 15,
],
],
'clusters' => [
'default' => [
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'timeout' => 15,
],
],
],
Based on info found here: https://github.com/nrk/predis/issues/480 - but needed to also replicate all 'default' config values in the options -> parameters group
REDIS_HOST, is pointing to the configuration endpoint in AWS elasticache's redis cluster.
I think the problem is that I'm trying to switch amz cloud service by service... ANd redis can only be accessed through the vpc which I'm not in this case.
I need to test is from an ec2 inside the vpc for testing.
I am trying to use ElasticCache Redis Cluster(Cluster mode enabled not sentinel) on Laravel-5.4.32 but getting below error:
1/1) ServerException
MOVED 13491 10.0.1.199:6379
My database.php looks like below:
'redis' => [
'client' => 'predis',
'cluster' => true,
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
REDIS_HOST value is been provided using .env file.
My application works fine with single redis instance.
Below configuration worked for me:
'redis' => [
'client' => 'predis',
'options' => [
'cluster' => 'redis',
],
'clusters' => [
'default' => [
[
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
],
],
Actually, this is clearly mentioned in laravel documentation: https://laravel.com/docs/5.4/redis#configuration
In yii2 I need to use memcache plugin I've installed this also will be shown in phpinfo but I get the following error when running the project:
Invalid Configuration – yii\base\InvalidConfigException - MemCache requires PHP memcache extension to be loaded.
Cache configuration
'cache' => [
'class' => 'yii\caching\MemCache',
'servers' => [
[
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 60,
],
],
]
Maybe you have got memcached instead of memcache. Configuration in this case should be:
'cache' => [
'class' => 'yii\caching\MemCache',
'useMemcached' => true, // <--- here
'servers' => [
[
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 60,
],
],
],
I want to put session and cache data into redis. This is my configuration in database.php:
'redis' => array(
'cluster' => false,
'default' => array(
'host' => '192.168.56.101',
'port' => 6379,
'database' => 0,
),
'session' => array(
'host' => '192.168.56.101',
'port' => 6379,
'database' => 1,
),
),
session.php:
return array(
'driver' => 'redis',
'connection' => 'session',
);
cache.php:
'driver' => 'redis',
However, where I write code like this:
Cache::remember('aa',1,function(){
return 'bb';
});
cache driver uses the same redis database as session driver does, which results in:
127.0.0.1:6379[1]> keys *
1) "aa"
2) "e0606244bec40b0352fb2b7b65d98049e49f6189"
Anyone knows how to force cache to use a specific redis connection? Or I have to mix them up together?
Introduction
Here is my note, for some other guy who running in to this problem, I think this is should be in the docs.
By default, redis gives you 16 separate databases, but laravel out of the box will try to use database 0 for both sessions and cache.
Our solution is to let Redis caching using database 0, and database 1 for Session, there for solving the session clear by running php artisan cache:clear problem.
Note: Tested at Laravel 5.1
1. Setting up Session Redis connection
Modify config/database.php, add session key to the redis option:
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'session' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 1,
],
],
2. Make use of the session connection
Modify config/session.php, change the following:
'connection' => null,
to:
'connection' => 'session',
3. Using Redis as session driver
Modify .env, change SESSION_DRIVER:
SESSION_DRIVER=redis
4. Testing out
Execute the following artisan command, then check your login state:
php artisan cache:clear
If the login state persists, voilà!
Laravel 5.5:
database.php should look like this:
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'session' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 1,
],
],
And in the session.php you have to update also the key "connection" to the right key. In this case 'session'
'connection' => 'session',
Laravel 5 now supports this.
https://github.com/laravel/framework/commit/d10a840514d122fa638eb5baa24c8eae4818da3e
You can select redis connection by modifying config/cache.php
'stores' => [
'redis' => [
'driver' => 'redis',
'connection' => 'your-connection-name',
],
],
Laravel 4 CacheManager does not support selecting redis connection.
What you need to do is to modify/extend CacheManager and override createRedisDriver() method.
Modify this line
return $this->repository(new RedisStore($redis, $this->getPrefix()));
To
return $this->repository(
new RedisStore($redis, $this->getPrefix(),
$this->app['config']['cache.redis'])
);
Now you can define your configuration in cache.php
'redis' => 'your-connection-name'