laravelredis-clusterpredisamazon-elasticache

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)

Error

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: enter image description here

And this is Elasticache Redis information: enter image description here

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

  • Solution: Changed with using **phpredis ** it works:

    1. Install php-redis in server:
    sudo yum -y install php-redis
    sudo systemctl restart php-fpm.service
    
    1. Change config:
      'redis' => [
    
            'client' => env('REDIS_CLIENT', 'phpredis'),
           ....
    ]
    

    Not sure why it doesn't work with predis. Even though the configuration is the same.