MOVED error
The key belongs to a hash slot that another cluster node serves.
A Redis cluster returns this error when you send a command to a node that doesn't serve the key. The error tells you which node does. A client that supports clusters reads the error, sends the command again to the right node, and updates its map of the cluster.
A cluster splits keys into 16384 hash slots, and each primary node serves some of the slots. The error gives the key's slot number and the address of the node that serves it:
MOVED 12182 127.0.0.1:6463
In client libraries
| Client library | Exception or error type | Message |
|---|---|---|
| redis-py | MovedError |
<slot> <endpoint>:<port>RedisCluster follows the redirect itself and raises this error only if it can't. |
| Jedis | JedisMovedDataException |
MOVED <slot> <endpoint>:<port>JedisCluster follows the redirect itself and raises this error only if it can't. |
| node-redis | SimpleErrorTest with err.message.startsWith('MOVED') |
MOVED <slot> <endpoint>:<port>createCluster follows the redirect itself, and throws MaxCommandRedirectionsError after 16 attempts by default. |
| Lettuce The async API wraps the exception in an ExecutionException (get()) or a CompletionException (join()). |
RedisCommandExecutionException |
MOVED <slot> <endpoint>:<port>RedisClusterClient follows the redirect itself, and raises this error after 5 redirects by default. |
| go-redis | redis.ErrorTest with redis.IsMovedError(err) |
MOVED <slot> <endpoint>:<port>ClusterClient follows the redirect itself, and returns this error after MaxRedirects attempts (3 by default). |
| ioredis | ReplyErrorTest with err.message.startsWith('MOVED') |
MOVED <slot> <endpoint>:<port> |
| StackExchange.Redis NRedisStack uses StackExchange.Redis, so it raises the same exceptions. The sync and async APIs raise the same exceptions. |
(none) |
When it connects to a cluster, StackExchange.Redis learns which node holds each slot and sends the command there, so no MOVED error reaches your code. |
| Predis | Predis\Response\ServerExceptionTest with $e->getErrorType() === 'MOVED' |
MOVED <slot> <endpoint>:<port> |
| redis-rb | Redis::CommandError |
MOVED <slot> <endpoint>:<port> (redis://<host>:<port>) |
| redis-rs The sync and async APIs raise the same errors. |
ErrorKind::Server(ServerErrorKind::Moved) |
Moved: <slot> <endpoint>:<port> |
Example
> GET foo
(error) MOVED 12182 127.0.0.1:6463
How to fix it
- Your client doesn't support clusters. Use a cluster client, which follows
MOVEDerrors for you. For example, in redis-py, useRedisClusterinstead ofRedis. See Connect to a Redis cluster. - You're using
redis-cli. Add the-coption, soredis-clifollows the error to the right node:redis-cli -c -h <host> -p <port>.
See MOVED redirection in the cluster specification.