Introducing Dragonfly Cloud! Learn More

Error: redis.clients.jedis.exceptions.jedismoveddataexception

What's Causing This Error

The 'redis.clients.jedis.exceptions.JedisMovedDataException' error is caused when a Redis cluster node has moved to a different slot. This indicates that the requested key resides on a different slot than the one requested initially. Redis uses a mapping function to determine the hash slot for a given key, and if the slot changes, Jedis throws this exception. This can occur during normal operation when the Redis Cluster redistributes slots due to adding or removing nodes from the cluster.

Solution - Here's How To Resolve It

To resolve this issue, you should catch the JedisMovedDataException and then retry the original command with the updated node information. You can obtain the new node using the "MOVED" response, which contains the IP and port for the new node. After obtaining the new node details, update your client configuration and retry the operation. Additionally, it's recommended to enable automatic redirection in the Jedis client so that it automatically redirects requests to the correct node without throwing exceptions. This can be done by setting the appropriate option in the JedisPoolConfig object. By enabling automatic redirection, your client can handle node failures and slot migrations seamlessly without requiring any manual intervention.

Was this content helpful?

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.