Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS ElastiCache Redis can't connect from Laravel nad from redis-cli

I'm having a problem connecting to ElastiCache Redis from Laravel application installed on EC2 instance or even using redis-cli from EC2 instance.

Laravel

I tried to use predis with configurations in database.php like

    'redis' => [
    'client' => 'predis',
    'default' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => 0,
        'read_write_timeout' => -1,
        'timeout' => 0
    ],
],

and got 'Error while reading line from the server. [tcp:server here]'

I tried with phpRedis extension with same configurations only change 'client' => 'phpredis' and got error read error on connection {"exception":"[object] (RedisException(code: 0): read error on connection at vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:69)

Redis cli

Using redis cli redis-cli -h host_here -p 6379 -a password_here I see prompt like host:6379> but typing any command throws error Error: Connection reset by peer

ElastiCache Redis configurations

enter image description here

My EC2 and elastic cache are in the same VPC and using telnet I can connect to redis instance

~$ telnet host 6379
Trying 172.31.23.113...
Connected to host.
Escape character is '^]'.

Thanks for any help!

like image 452
Bogdan Dubyk Avatar asked Dec 07 '17 13:12

Bogdan Dubyk


1 Answers

I know this is pretty old but I was having the same issue myself. If anyone encounters this issue then see the solution here and here.

It seems that when you enable Encryption in-transit in AWS Elasticache it prevents you from using redis-cli as it doesn't support TLS connections. Switching to another client should work. This answer has a list of TLS enabled clients.

Edit:

Did some more digging and found that using stunnel you can wrap your connection of redis-cli with ssl. Here is a guide for doing it.

like image 127
Guy Grin Avatar answered Sep 21 '22 00:09

Guy Grin