Skip to content

timeout connecting to redis hosted on aws ElastiCache #1001

@Jun711

Description

@Jun711

Hi,

I have a redis server hosted by aws using aws ElastiCache. When I try to connect to it using a lambda and on my local machine, it gives 'timeout connecting to server' error. However, my colleague could connect to this redis using another client in PHP.
I wonder what I did wrong.

try:
        redisClient = redis.Redis(host='***.use1.cache.amazonaws.com', port=6379, db=0, socket_timeout=10)
        print(redisClient)
        try:
            print(redisClient.ping())
            print(redisClient.set('foo','bar'))
            # r.get('foo')
        except Exception as e:
            print('get set error: ', e)
    except Exception as e:
        print('redis err: ', e)

// redisClient Redis<ConnectionPool<Connection<host=***.use1.cache.amazonaws.com,port=6379,db=0>>>

// get set error:  Timeout connecting to server for ping or set

Without setting the socket_timeout parameter, it will time out based on redis-py operation timeout:
Error 60 connecting to ***.use1.cache.amazonaws.com:6379. Operation timed out.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions