Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Obydul's avatar

How to Integrate Amazon ElastiCache (Redis) Serverless?

Hi,

I'm currently using Amazon ElastiCache, and it's working fine. Now, I want to integrate Serverless ElastiCache.

I've entered REDIS_HOST and REDIS_PORT similar to the traditional Redis/ElastiCache configuration, but it doesn't seem to work for Serverless.

Can anyone help?

Thanks in advance.

0 likes
8 replies
nexxai's avatar

Are you also setting the REDIS_PASSWORD environment variable? You're using an otherwise-publicly accessible instance, Amazon should be locking it down with some sort of authentication.

Obydul's avatar

@nexxai Thank you. I've updated the Redis configuration and it works.

But I'm facing another issue with Horizon queue:

Predis\Response\ServerException CROSSSLOT Keys in request don't hash to the same slot /var/www/html/vendor/predis/predis/src/Client.php 370  

The config

config/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_'),
    ],
    
    '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' => 0,
            ],
        ],
        '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' => 0,
            ],
        ],
    ],
],

.env:

REDIS_SCHEME=tls
REDIS_HOST=*****.serverless.use2.cache.amazonaws.com
REDIS_PORT=6379
1 like
nexxai's avatar

@Obydul Are you actually using a Redis cluster?

If not, remove the clusters key and move the default and cache keys back one tab left, to be children of the 'redis' entry.

Obydul's avatar

@nexxai Yh Redis cluster. Amazon ElastiCache Serverless is a cluster.

1 like
berusjamban's avatar

I also having the same problem. I already used the default redis connection.

devdex's avatar

Me too having a problem with redis serverless with laravel I tried this, added scheme.

'default' => [ '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', '0'), 'scheme' => 'tls', ],

but still I encounter an error.

ademtepe's avatar
'redis' => [

    'client' => env('REDIS_CLIENT', 'phpredis'),

    'default' => [
        'scheme' => 'tls',
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'port' => env('REDIS_PORT', '6379'),
        'database' => env('REDIS_DB', '0'),
    ],

    'cache' => [
        'scheme' => 'tls',
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'port' => env('REDIS_PORT', '6379'),
        'database' => env('REDIS_CACHE_DB', '1'),
    ],

],

With the configuration above I had the following error using AWS Elasticache for Redis Serverless:

class : RedisException file : /var/app/current/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php line : 116 message : CROSSSLOT Keys in request don't hash to the same slot

I was searching solution for that error. One of the phrases I used for search "laravel settings for elasticache serverless redis" brought me here.

So, first I wanted to try you exact configuration @obydul . I used your "exact" configuration and this time I faced the following error doing the exact same operations:

class : Predis\NotSupportedException file : /var/app/current/vendor/predis/predis/src/Connection/Cluster/RedisCluster.php line : 354 message : Cannot use 'EVAL' with redis-cluster.

So, this time, I started searching for solution to this error and found it on Stack Overflow.

The answer is simply saying to put curly braces around the name of redis queue which resides in config/queue.php and queue => connections => redis => queue.

SOLUTION:

So, this:

'queue' => env('REDIS_QUEUE', '{default}'),

instead of this:

'queue' => env('REDIS_QUEUE', 'default'),

It worked for me amazingly.

Now, I'm going to try it with phpredis (pecl redis).

Hope this helps and solves the issue for others who wrote here.

ADDITION:

Unfortunately the solution above didn't work for phpredis (pecl redis) and I started to get the following error "for every request" this time:

class : RedisClusterException file : /var/app/current/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php line : 116 message : Error processing response from Redis node! context : null

Finally, I went back to my initial config/database.php configuration and now everything's working.

NOTE: I have realized that my answer may have been somehow long and complicated, I may edit to make it neat later on.

1 like

Please or to participate in this conversation.