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?
Other Common Redis Errors (with Solutions)
- could not connect to redis at 127.0.0.1:6379: connection refused
- redis error server closed the connection
- redis.exceptions.responseerror: value is not an integer or out of range
- redis.exceptions.responseerror moved
- redis-server failed to start advanced key-value store
- spring boot redis unable to connect to localhost 6379
- unable to configure redis to keyspace notifications
- could not get resource from pool redis
- failed to restart redis service unit redis service not found
- job for redis-server.service failed because a timeout was exceeded
- failed to start redis-server.service unit redis-server.service is masked
- failed to stop redis-server.service unit redis-server.service not loaded
Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost