# redis.exceptions.ResponseError：MOVED 1234 192.168.1.1:6379

- **ID:** `database/redis-cluster-slot-migration`
- **领域:** database
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Redis 6.2 | active | — | — |
| Redis 7.0 | active | — | — |
| Redis 7.2 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — The client will keep hitting the same wrong node and get MOVED errors repeatedly; the slots must be refreshed. (95% 失败率)
- **** — This can break cluster consistency; the slot might be owned by another node, causing data loss or split-brain. (80% 失败率)
- **** — This treats the cluster as a standalone instance; MOVED errors will still occur for keys in non-local slots. (100% 失败率)
