如何使用 ioredis 连接到 AWS Redis 集群?

huangapple go评论53阅读模式
英文:

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

我最终使用了ioredisCluster构造函数,并且它按预期工作。我还没有使用“配置端点”,而是使用了每个分片的主节点列表,如下所示:

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([
  &#39;https://&lt;node1-master&gt;&#39;,
  &#39;https://&lt;node2-master&gt;&#39;,
  ...
], 
{
  scaleReads: &#39;slave&#39;,
})

huangapple
  • 本文由 发表于 2023年5月17日 20:58:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76272382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定