Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predis with laravel 5.5 "No connections available in the pool in Aggregate/RedisCluster.php:337 "

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!

like image 746
Zeshan Avatar asked Nov 06 '22 23:11

Zeshan


1 Answers

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.

like image 109
Jonathan Baker Avatar answered Nov 15 '22 15:11

Jonathan Baker