ASK error
The key's hash slot is moving to another cluster node, and the key may already be there.
A Redis cluster returns this error while a hash slot is moving from one node to another, for example, while you reshard the cluster. The key you asked for isn't on the node you sent the command to, so it may already be on the new node. The error gives the slot number and the new node's address:
ASK 8000 127.0.0.1:6461
In client libraries
| Client library | Exception or error type | Message |
|---|---|---|
| redis-py | AskError |
<slot> <endpoint>:<port>RedisCluster follows the redirect itself and raises this error only if it can't. |
| Jedis | JedisAskDataException |
ASK <slot> <endpoint>:<port>JedisCluster follows the redirect itself and raises this error only if it can't. |
| node-redis | SimpleErrorTest with err.message.startsWith('ASK') |
ASK <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 |
ASK <slot> <endpoint>:<port>RedisClusterClient follows the redirect itself, and raises this error after 5 redirects by default. |
| go-redis | redis.ErrorTest with redis.IsAskError(err) |
ASK <slot> <endpoint>:<port>ClusterClient follows the redirect itself, and returns this error after MaxRedirects attempts (3 by default). |
| ioredis | ReplyErrorTest with err.message.startsWith('ASK') |
ASK <slot> <endpoint>:<port> |
| Predis | Predis\Response\ServerExceptionTest with $e->getErrorType() === 'ASK' |
ASK <slot> <endpoint>:<port> |
| redis-rb | Redis::CommandError |
ASK <slot> <endpoint>:<port> (redis://<host>:<port>) |
| redis-rs The sync and async APIs raise the same errors. |
ErrorKind::Server(ServerErrorKind::Ask) |
Ask: <slot> <endpoint>:<port> |
Example
During the move, the old node no longer has the key:
> GET user:{42}:cart
(error) ASK 8000 127.0.0.1:6461
How to fix it
- Your client doesn't support clusters. Use a cluster client, which handles
ASKerrors for you, as it doesMOVEDerrors. Inredis-cli, add the-coption. - You handle redirects yourself. Send
ASKINGto the node in the error, and then send the command again to that node. WithoutASKING, the new node replies withMOVEDand points you back to the old node. Unlike withMOVED, don't update your map of the cluster. The slot still belongs to the old node until the move finishes, so send later commands to the old node first.
See ASK redirection in the cluster specification.