MOVED: The key lives on another cluster node
In Redis Cluster the key's hash slot is owned by a different node, which replies with the slot number and the address that owns it.
- Error prefix
MOVED
它的意思
MOVED is how Redis Cluster routes. Every key maps to one of 16384 slots (CRC16 of the key modulo 16384), each slot belongs to exactly one node, and a node that receives a command for a slot it does not own refuses it with MOVED slot host:port, telling the client where the key actually lives.
A cluster-aware client follows the redirect and re-sends to the reported endpoint. You see the error itself when the client is not cluster-aware (plain redis-cli without -c, a naive connection pool), when a resharding changed the slot map and a client has not refreshed yet, or when you point at one node deliberately for debugging. MOVED is normal protocol traffic, not a fault: the command did not run, but the cluster told you exactly where to run it.
常见原因
- A cluster-unaware client sent the command to a node that does not own the key's slot.
- The slot map changed through resharding or failover, and the client is still using its cached map.
- During maintenance you connected to a single node directly instead of through the cluster.
Find the cause
redis-cli -p 7000 CLUSTER KEYSLOT foo redis-cli -p 7000 CLUSTER MYID redis-cli -p 7000 CLUSTER SLOTS # Compare the owner of slot 12182 with the endpoint named in the MOVED reply
Anatomy of a MOVED reply
| MOVED | The prefix: this node refused the command and named the slot's owner. |
|---|---|
| 12182 | The hash slot the key maps to, CRC16 of the key modulo 16384. |
| 127.0.0.1:7002 | The endpoint that owns the slot now; re-send the command there. |
如何修复它
-
Find which slot the key hashes to, then ask the cluster who owns it:
redis-cli -p 7000 CLUSTER KEYSLOT foo # (integer) 12182 redis-cli -p 7000 CLUSTER SLOTS
-
Use a cluster-aware client, or redis-cli with -c, which follows the redirect for you:
redis-cli -c -p 7000 SET foo bar # -> Redirected to slot [12182] located at 127.0.0.1:7002 # OK
-
If errors persist after a reshard, force the client to rebuild its slot map by reconnecting; most libraries also refresh on every MOVED they receive.
Other ways to handle it
Hash tags keep related keys in one slot: keys like {user:1000}:profile and {user:1000}:session hash on the part in braces, so multi-key commands on one user stop bouncing between nodes. For application code, a cluster-aware client removes the problem entirely instead of handling it after the fact.
安全地复现它
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 --cluster-replicas 0 redis-cli -p 7000 SET foo bar # (error) MOVED 12182 127.0.0.1:7002 redis-cli -c -p 7000 SET foo bar # OK (the redirect was followed)
问题
Is MOVED a problem I need to fix?
Not on its own. Cluster-aware clients follow it automatically. Act only when a client keeps failing: it is not following redirects, or its slot map has gone stale.
How is the slot number computed?
CRC16 of the key modulo 16384. If the key contains {braces}, only the part inside them is hashed, which is how hash tags pin keys to the same slot.
相关错误
ASKThe key is migrating to another nodeCROSSSLOTMulti-key command spans two slotsCLUSTERDOWNThe cluster cannot serve this slot
More cluster and replication errors
READONLYWrite rejected on a read only replicaMASTERDOWNStale data is not allowed to be servedTRYAGAINSlot is rehashing, retry the commandNOREPLICASToo few healthy replicas to write
代码和消息文本来自 Redis documentation and source code。浏览完整的 Redis error list 或者 搜索每个数据库错误.
Work on Redis in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Redis and the other databases you use.
本页文字和数据: CC BY 4.0,请注明出处 SQLly (sqlly.app)。 代码和 SQL 片段: MIT. 许可详情 引用的错误消息文本归其数据库厂商所有。