MOVED
communication
protocol_error
ai_generated
true
MOVED 12182 10.0.0.1:6379:Redis 集群重定向到不同节点
MOVED 12182 10.0.0.1:6379: Redis cluster redirect to different node
ID: communication/redis-cluster-moved-redirect
88%修复率
86%置信度
1证据数
2023-09-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Redis 6.2 | active | — | — | — |
| Redis 7.0 | active | — | — | — |
| Redis 7.2 | active | — | — | — |
| ioredis 5.3 | active | — | — | — |
| redis-py 4.5 | active | — | — | — |
根因分析
Redis 集群客户端将命令发送到不拥有该键哈希槽的节点,且客户端未使用智能客户端路由或集群感知的连接池。
English
Redis cluster client sent a command to a node that does not own the key's hash slot, and the client is not using smart client-side routing or cluster-aware connection pooling.
官方文档
https://redis.io/docs/reference/cluster-spec/解决方案
-
使用支持 Redis 集群的客户端库自动处理 MOVED 重定向,例如 ioredis Cluster:`new Redis.Cluster([{ host: '10.0.0.1', port: 6379 }])`,它会维护槽到节点的映射。 -
在客户端配置中启用集群模式并自动刷新槽信息,例如在 redis-py 中:`rediscluster.RedisCluster(startup_nodes=[{'host':'10.0.0.1','port':6379}], skip_full_coverage_check=True)`。 -
如果使用非集群感知客户端,实现手动重试并计算槽位:使用 CRC16 对键取模 16384 计算哈希槽,然后直接连接到正确节点。
无效尝试
常见但无效的做法:
-
Manually redirect the client to the node IP in the MOVED error without updating the cluster topology
70% 失败
The cluster topology may change again; manual redirection is not scalable and can cause further MOVED errors.
-
Disable cluster mode and connect to a single Redis instance
90% 失败
Defeats the purpose of clustering; data may be incomplete or inconsistent across nodes.
-
Increase connection timeout in client configuration
85% 失败
Timeout does not address the routing issue; MOVED is a protocol-level redirect, not a timeout.