英文:
How to connect to an AWS Redis cluster with ioredis?
问题
I have an AWS Elasticache Redis cluster consisting of two shards, with each having one primary node and one replication node (total of four nodes).
How do I instantiate an ioredis
Cluster
object to connect and use all of these nodes?
The ioredis documentation indicates that the Cluster
should be instantiated with a list of cluster nodes, like this:
const cluster = new Redis.Cluster([ { port: 6380, host: "127.0.0.1", }, { port: 6381, host: "127.0.0.1", }, ]);
So, do I include all 4 of the AWS Redis endpoints? I.e., both primary and replication nodes, from each shard?
The documentation also says
does not need to enumerate all your cluster nodes, but a few so that if one is unreachable the client will try the next one, and the client will discover other nodes automatically when at least one node is connected
Does this mean I can include just one endpoint, and ioreds
will figure it out?
Or, do I use the AWS Redis Configuration endpoint
? If not, what is this for?
Thanks!
英文:
I have an AWS Elasticache Redis cluster consisting of two shards, with each having one primary node and one replication node (total of four nodes).
How do I instantiate an ioredis
Cluster
object to connect and use all of these nodes?
The ioredis documentation indicates that the Cluster
should be instantiated with a list of cluster nodes, like this:
const cluster = new Redis.Cluster([
{
port: 6380,
host: "127.0.0.1",
},
{
port: 6381,
host: "127.0.0.1",
},
]);
So, do I include all 4 of the AWS Redis endpoints? I.e., both primary and replication nodes, from each shard?
The documentation also says
> does not need to enumerate all your cluster nodes, but a few so that if one is unreachable the client will try the next one, and the client will discover other nodes automatically when at least one node is connected
Does this mean I can include just one endpoint, and ioreds
will figure it out?
Or, do I use the AWS Redis Configuration endpoint
? If not, what is this for?
Thanks!
答案1
得分: 0
我最终使用了ioredis
的Cluster
构造函数,并且它按预期工作。我还没有使用“配置端点”,而是使用了每个分片的主节点列表,如下所示:
new Cluster([
'https://<node1-master>',
'https://<node2-master>',
...
],
{
scaleReads: 'slave',
})
英文:
I ended up using the ioredis
Cluster
contructor, and this works as expected. I also did not use the "Configuration endpoint", but instead a list of the master node from each shard, like this:
new Cluster([
'https://<node1-master>',
'https://<node2-master>',
...
],
{
scaleReads: 'slave',
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论