Redirect for cluster slot migration
Production Risk
Low if clients are cluster-aware. High if they are not.
This is a temporary redirection used during cluster resharding. It indicates that the slot for a key is being migrated from one node to another. The client must send an ASKING command to the destination node before sending the actual command.
- 1A cluster resharding operation is in progress (`CLUSTER SETSLOT MIGRATING`).
- 2The specific key being requested has not yet been moved to the destination node.
- 3The client is attempting to access a key in a slot that is currently being migrated.
A client requests a key 'mykey' from Node A, but the slot for 'mykey' is being migrated to Node B. The key itself hasn't moved yet, so Node A issues an ASK redirect.
# On Node A, while slot for 'mykey' is migrating to B GET mykey
expected output
(error) ASK 12345 192.168.1.101:6379
Fix 1
Use a cluster-aware client library
WHEN Connecting to any Redis Cluster
// Client handles this automatically. The logic is: // 1. Receive ASK redirection to Node B // 2. Connect to Node B // 3. Send ASKING command // 4. Send original command (e.g., GET mykey) // 5. Receive reply from Node B
Why this works
Proper cluster clients understand the ASK protocol. Unlike MOVED, an ASK redirect is for a single command only. The client must prefix its next command to the target node with the ASKING command, which signals that it is aware of the ongoing migration.
Fix 2
Use redis-cli with the -c flag
WHEN Using the command-line interface
redis-cli -c -p 6379
Why this works
The `-c` flag enables cluster mode in the CLI, which automatically handles both MOVED and ASK redirections by sending the `ASKING` command when required.
✕ Treat ASK like MOVED
ASK is a one-time redirection for a migrating slot. If you update your client's slot map permanently (as you would for MOVED), you will incorrectly send all future traffic for that slot to the destination node, even for keys that haven't migrated yet.
Redis Cluster resharding and migration logic.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev