Connecting redis cluster using Laravel giving no connection available in the pool - laravel

I want to connect redis cluster from Laravel but I am getting No connections available in the pool. My databaase.php looks like
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'clusters' => [
'default' =>
[
[
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
]],
'options' => [
'cluster' => 'redis', // This tells Redis Client lib to follow redirects (from cluster)
]
],
]
But with this settings, I am getting No connections available in the pool. But if I just connect redis cluster using cli, I can successfully connect. So I believe there is something wrong with my laravel configuration that I am still unable to solve. Any help?
Solution
Hi guys, it was a configuration issue. I was using wrong port. The default port is 6379 and I was mistakenly using another port number.

Moving the options to the parent array should solve your problem.
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => 'redis'
]
'clusters' => [
'default' => [
[
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
]
]
]
]

What about adding scheme and moving options ?
'redis' => [
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => 'redis'
],
'clusters' => [
'default' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
]
]
]
]

Related

AWS ElastiCache Redis can't connect from Laravel, show error: No connections available in the pool

Setup Laravel 8.x cache with AWS Elasticache Redis cluster:
i have tried many configure that i found. but none of them work.
i tried connecting Elasticache Redis cluster from redis-cli, it works with Ping pong.
But not working with laravel: (Error: No connections available in the pool)
And this is my config:
'redis' => [
'cluster' => true,
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
// 'ssl' => ['verify_peer' => false], => have tried, it not working
/*
'parameters' => [ => have tried, it not working
'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' => env('REDIS_CACHE_DB', 0),
'read_write_timeout' => 30,
],
],
'cache' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
]
],
'options' =>[
'cluster' =>'redis',
]
],
],
I have tried connecting Elasticache with Redis cli in Ec2, and it can connect:
And this is Elasticache Redis information:
This is my .env:
CACHE_DRIVER=redis
REDIS_HOST=xxxxx.xxxxx.clustercfg.xxxxx.cache.amazonaws.com
REDIS_PASSWORD=null
REDIS_PORT=6379
By the way, i connect with Configuration Endpoint (not Primary Endpoint)
and i have install "predis/predis" in composer.json.
I changed a lot of configurations that I found on the Google, but it doesn't work. Please help!!
Thanks for reading.
Solution:
Changed with using **phpredis ** it works:
Install php-redis in server:
sudo yum -y install php-redis
sudo systemctl restart php-fpm.service
Change config:
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
....
]
Not sure why it doesn't work with predis. Even though the configuration is the same.

No connections available in the pool, Laravel predis

I have the error "No connections available in the pool" under laravel 7, php7.4 and redis server on AWZ elasticache.
Here my .env :
REDIS_CLIENT=predis
REDIS_SCHEME=tls
REDIS_HOST=clustercfg.xxx.xxx.xxx.cache.amazonaws.com
REDIS_PASSWORD=xxx
REDIS_PORT=6379
my config/database.php :
'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,
]
],
'cache' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
]
],
],
],
clustercfg.xxx.xxx.xxx.cache.amazonaws.com is my configuration endpoint and REDIS_PASSWORD my AUTH token
I have basically copied the solution of Predis with laravel 5.5 "No connections available in the pool in Aggregate/RedisCluster.php:337 "
but problem is not resolved.
I have looked at the vpc security group in amazon and basically all ports are opened :

No connections available in the pool, Laravel and Redis

I've setup a redis cluster with 6 nodes locally on my ubuntu 18.04, starting from 127.0.0.1:7000 to 127.0.0.1:7006, with the default 'utils/create-cluster' script that comes with redis binaries.
I'm having issues setting up redis on a laravel 5.7 application, I'm trying to make a request to an endpoint and I'm getting the following error
No connections available in the pool at line 337
myApp/vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php
It's exactly the same error from here --> Predis with laravel 5.5 "No connections available in the pool in Aggregate/RedisCluster.php:337 "
But that answer has not solved my issue, nor the referred link --> https://github.com/nrk/predis/issues/480
My .env file has the following values
BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=redis
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=7000
And my app/database.php is as follows
'redis' => [
'client' => 'predis',
'cluster' => true,
'options' => [
'cluster' => 'redis',
],
'clusters' => [
'default' => [
[
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DB', 0),
],
],
'cache' => [
[
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
],
]
],
],
I'd appreciate some help!
After a lot of googling and trial and error, I managed to solve the problem by changing the file config/cache.php at the following lines
error:
'redis' => [
'driver' => 'redis'
'connection' => 'cache'
]
working:
'redis' => [
'driver' => 'redis'
'connection' => 'default'
]

Laravel separate read/write operations for Redis?

I have a Redis cluster running inside Kubernetes. A Redis cluster can only have 1 master and N slaves. Is it possible to have multiple Redis connections inside Laravel for reading and writing? so I can write to the master and read from a slave. It's possible for 'normal' databases:
'mysql' => [
'read' => [
'host' => ['192.168.1.1'],
],
'write' => [
'host' => ['196.168.1.2'],
],
'....' => .....
]
Is there anyway to achieve this for Redis?
Thankyou,
You can change which connection is used with the connection method which will return a Redis instance, e.g:
$redis = Redis::connection('read');
$redis->get('example');
You would configure the different connections in the same way you would for MySQL.
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
'read' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6380),
'database' => 0,
],
],

What does the setting queue at Laravel 5.5 config/queue.php do?

What does the 'queue' => 'default' setting do at config/queue.php?
It seems like it does not affect anything.
In config/queue.php my queue configuration is ga-fetcher-queue.
This is my config:
return [
'default' => 'redis',
'connections' => [
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'ga-fetcher-queue',
'retry_after' => 360,
],
],
'failed' => []
];
My redis config at config/database.php is 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,
],
]

Resources