Error: redis moved error

What's Causing This Error

The 'redis moved error' occurs when a Redis Cluster node gets a request for a key that’s no longer under its jurisdiction. The issue typically occurs when there is an addition or removal of cluster nodes, and as a result, the slot mapping of keys changes. Redis Cluster uses hash functions to determine which node has ownership of each key. When this map changes, some keys could end up belonging to a different node.

Solution - Here's How To Resolve It

Resolving the 'redis moved error' involves updating the client code to use the correct Redis node for the requested key. One possible solution is to configure the client library to support automatic redirection to the correct node whenever a 'moved' error occurs. Most Redis client libraries come with this built-in feature.

Another way to address the issue is by using a Redis client that employs consistent hashing such as twemproxy to evenly distribute requests across multiple Redis nodes. Consistent hashing assures that the same key always goes to the same Redis node, even if nodes get added or removed from the cluster.

Lastly, you can manually update the keys, moving them to their new location employing the Redis 'MOVE' command. However, accomplishing this approach requires comprehensive knowledge of the Redis cluster topology and could be time-consuming if many keys need to be moved.

Was this content helpful?

Start building today

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