database protocol_error ai_generated true

redis.exceptions.ResponseError:MOVED 1234 192.168.1.1:6379

redis.exceptions.ResponseError: MOVED 1234 192.168.1.1:6379

ID: database/redis-cluster-slot-migration

其他格式: JSON · Markdown 中文 · English
90%修复率
84%置信度
1证据数
2023-08-12首次发现

版本兼容性

版本状态引入弃用备注
Redis 6.2 active
Redis 7.0 active
Redis 7.2 active

根因分析

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

English

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

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 95% 失败

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

  2. 80% 失败

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

  3. 100% 失败

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