Search code examples
redis-clusterioredis

Does ioredis client cache the map between hash slots and nodes addresses?


In Redis cluster tutorial, it is stated that

"A serious client is able to do better than that, and cache the map between hash slots and nodes addresses, to directly use the right connection to the right node. The map is refreshed only when something changed in the cluster configuration, for example after a failover or after the system administrator changed the cluster layout by adding or removing nodes."

Does ioredis cache the map between hash slots and nodes addresses?


Solution

  • Yes, ioredis caches the slots for you and handles the moved and ask error to update the slot cache.

    The related code is here:

    https://github.com/luin/ioredis/blob/master/lib/cluster/index.js#L387-L398