I'm new to Redis and Amazon MemoryDB. Currently I'm able to spin up a Redis Cluster using Amazon MemoryDB, following the aws document.
redis-cli
works for me to link to my redis cluster (from another EC2 instance inside of the VPC):
>> redis-cli -c --tls -h my-redis-cluster.idocmu.memorydb.us-west-2.amazonaws.com -p 6379
my-redis-cluster.idocmu.memorydb.us-west-2.amazonaws.com:6379> PING
PONG
When I tried to connect to it using python/Java in the same EC2 instance, connections never work:
>> python3
Python 3.7.16 (default, Dec 15 2022, 23:24:54)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>> r = redis.RedisCluster(host="my-redis-cluster.idocmu.memorydb.us-west-2.amazonaws.com", port=6379)
... python3 fronzen here...
The same for Jedis the Java Client:
import redis.clients.jedis.Jedis;
Jedis jedis = new Jedis("my-redis-cluster.idocmu.memorydb.us-west-2.amazonaws.com", 6379);
jedis.set("key100", "value100");
... java connection timeout here...
Is there something I missed? Why redis-cli is able to connect while my scripts cannot?
Also tried some other clients listed in Redis page: https://redis.io/resources/clients/ Redission also failed to connect. It seems something must be wrong with my setup. But I just cannot understand why redis-cli is able to connect.
That's because when you connect with recis-cli
, you provide --tls
(means your cluster is configured with in-transit encryption).
However when you connect with the other clients, you don't use TLS. In order to connect with redis-py
for example, you need to provide ssl=True
:
redis.RedisCluster(host="my-redis-cluster.idocmu.memorydb.us-west-2.amazonaws.com", port=6379, ssl=True)
See examples here.