Search code examples
redisredis-clusterioredis

Can ioredis client continue working if a cluster node from the initial connection dies?


When connecting to a redis cluster with ioredis (https://github.com/luin/ioredis) you only need to specify one node e.g. with a three node cluster

127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002

You can connect using simply:

new Redis.Cluster([{
  port: 7000,
  host: '127.0.0.1'
}])

If the :7000 node dies and you replace it with a different node, doing something like:

redis-trib.rb call 127.0.0.1:7001 cluster forget [node_id of :7000]
redis-trib.rb add-node 127.0.0.1:7003 127.0.0.1:7001
redis-trib.rb fix 127.0.0.1:7001

Will ioredis be able to continue working (accepting that the data from the :7000 is lost), will it ever need to be able to contact 127.0.0.1:7000 again or is that only for the initial connection?

From my experiments it does seem that this scenario works and the answer to my question is yes, but I want to check that this is expected and a supported situation.


Solution

  • When connecting to a cluster, ioredis will ask the :7000 for the node list of the cluster, and after that ioredis is able to discover the new node and handle the failover. So, the answer is yes if the :7000 dies after the node list being fetched.