database protocol_error ai_generated true

redis.exceptions.ResponseError: MOVED 1234 192.168.1.1:6379

ID: database/redis-cluster-slot-migration

Also available as: JSON · Markdown · 中文
90%Fix Rate
84%Confidence
1Evidence
2023-08-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Redis 6.2 active
Redis 7.0 active
Redis 7.2 active

Root Cause

Redis Cluster client sent a request to the wrong node for a given hash slot; the node responds with MOVED redirection indicating the correct node, but the client is not using cluster-aware routing or the cluster topology has changed.

generic

中文

Redis 集群客户端将请求发送到错误的节点以获取给定的哈希槽;节点响应 MOVED 重定向指示正确的节点,但客户端未使用集群感知路由或集群拓扑已更改。

Official Documentation

https://redis.io/docs/reference/cluster-spec/

Workarounds

  1. 95% success Switch from redis.StrictRedis to redis.cluster.RedisCluster: from redis.cluster import RedisCluster; rc = RedisCluster(host='mycluster', port=6379). This handles MOVED redirections automatically.
    Switch from redis.StrictRedis to redis.cluster.RedisCluster: from redis.cluster import RedisCluster; rc = RedisCluster(host='mycluster', port=6379). This handles MOVED redirections automatically.
  2. 85% success Call rc.cluster_slots() or use the CLUSTER SLOTS command to get current slot-to-node mapping, then update client routing table.
    Call rc.cluster_slots() or use the CLUSTER SLOTS command to get current slot-to-node mapping, then update client routing table.
  3. 80% success Run redis-cli -h any_node CLUSTER NODES to see all nodes and slots. If slots are missing, rebalance: redis-cli --cluster rebalance 192.168.1.1:6379.
    Run redis-cli -h any_node CLUSTER NODES to see all nodes and slots. If slots are missing, rebalance: redis-cli --cluster rebalance 192.168.1.1:6379.

中文步骤

  1. Switch from redis.StrictRedis to redis.cluster.RedisCluster: from redis.cluster import RedisCluster; rc = RedisCluster(host='mycluster', port=6379). This handles MOVED redirections automatically.
  2. Call rc.cluster_slots() or use the CLUSTER SLOTS command to get current slot-to-node mapping, then update client routing table.
  3. Run redis-cli -h any_node CLUSTER NODES to see all nodes and slots. If slots are missing, rebalance: redis-cli --cluster rebalance 192.168.1.1:6379.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    The client will keep hitting the same wrong node and get MOVED errors repeatedly; the slots must be refreshed.

  2. 80% fail

    This can break cluster consistency; the slot might be owned by another node, causing data loss or split-brain.

  3. 100% fail

    This treats the cluster as a standalone instance; MOVED errors will still occur for keys in non-local slots.