// Redis error reference

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
類別
Cluster and replication
錯誤訊息
MOVED 12182 127.0.0.1:7002

它的意義

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

MOVEDThe prefix: this node refused the command and named the slot's owner.
12182The hash slot the key maps to, CRC16 of the key modulo 16384.
127.0.0.1:7002The endpoint that owns the slot now; re-send the command there.

如何修正

  1. 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
  2. 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
  3. 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.

相關錯誤

More cluster and replication errors

程式碼和訊息文字來自 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. 授權詳情 引用的錯誤訊息文字歸其資料庫廠商所有。