英文:
What's the recommended way to connect to Amazon MemoryDB for Redis programmatically?
问题
I'm new to Redis and Amazon MemoryDB.
目前,我能够使用Amazon MemoryDB启动Redis集群,按照aws文档进行操作。
redis-cli
对我来说可以用于连接到我的Redis集群(来自VPC内的另一个EC2实例):
>> 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
但是,当我尝试在同一台EC2实例中使用Python/Java连接时,连接从未成功:
>> python3
Python 3.7.16 (默认,2022年12月15日,23:24:54)
[GCC 7.3.1 20180712(Red Hat 7.3.1-15)] 在 Linux 上
键入"help"、"copyright"、"credits"或"license"以获取更多信息。
>>> import redis
>>> r = redis.RedisCluster(host="my-redis-cluster.idocmu.memorydb.us-west-2.amazonaws.com", port=6379)
... python3 在这里卡住了...
对于Jedis Java客户端也是一样的:
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 连接超时在这里...
我是否遗漏了什么?
为什么redis-cli
能够连接,而我的脚本却不能?
我还尝试了Redis页面上列出的其他客户端:
https://redis.io/resources/clients/
Redission也无法连接。
似乎我的设置必定有问题。但我只是无法理解为什么redis-cli
能够连接。
英文:
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.
答案1
得分: 3
这是翻译好的部分:
"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."
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论