// 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
Categoria
Cluster and replication
Mensagem de erro
MOVED 12182 127.0.0.1:7002

O que significa

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.

Causas comuns

  • 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.

Como corrigir

  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.

Reproduza com segurança

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)

Perguntas

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.

Erros relacionados

More cluster and replication errors

O código e o texto da mensagem são de Redis documentation and source code. Veja toda a Redis error list ou pesquise todos os erros do banco de dados.

// menos erros, correções mais rápidas

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.

Texto e dados desta página: CC BY 4.0, com crédito ao SQLly (sqlly.app). Código e trechos SQL: MIT. Detalhes da licença O texto citado das mensagens de erro pertence ao fornecedor do banco de dados.