2

I am using laravel 5.2 and having an architecture of multi-server autoscaling. I want to have session and cache in a centralized location. I want to use AWS elasticache for the same.

I have setup an elasticache Redis cluster having following options :

Parameter group : default.redis.3.2.cluster.on Shards : 3 Total Nodes : 9

In laravel session configuration I have set redis as the session driver.

In database.php where redis configuration is set, i have used following :

REDIS_HOST=my_aws_elasticache_configuration_endpoint REDIS_PASSWORD=null REDIS_PORT=6379 .

When I try to use it, I get following error :

MOVED 13841 some_ip_address_of_aws:6379

I tried using local redis and it worked, so predis is working properly. I tried to check the solutions online, but not able to get the solution. I believe that the configuration endpoint is trying to redirect the redis connection to an available node url out of the 9 nodes I have. However, I have anticipated that AWS should do it internally and not throw exception. Can anyone help me?

1 Answer 1

2

I finally got an answer, we need to get the cluster mode on in database settings and set new cluster option to redis. This is how the redis config in database.php looks like :

'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,
            ],
        ],
    ],
],

If you have password then you can replace options array with this :

 'options' => [
        'cluster' => 'redis',
        'parameters' => ['password' => env('REDIS_PASSWORD', null)],
    ],
Sign up to request clarification or add additional context in comments.

1 Comment

A word to the wise: If you enable TLS (encryption in transit) for Redis, you'll also need to have 'scheme' => env('REDIS_SCHEME', 'tcp') in the parameters array. Set this to 'tls' in your .env. If you're using AWS Elasticache, you'll also need 'ssl' => ['verify_peer' => false] in the options array as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.