问题描述:redis在添加键值时报错"(error) MOVED....",如下所示:
数据库:redis 6.2.5
架构:三主三从
1、异常重现
192.168.133.97:6001> set k1 v1
(error) MOVED 12706 192.168.133.99:6001
--集群信息
192.168.133.97:6001> cluster nodes
b98cc2012f531244c29e2633f3d40ffc0c8bb271 192.168.133.98:6002@16002 slave dddef88bf455737ced62b5616a6c2385a378904b 0 1697364806758 1 connected
db41da6a340ae7a4d0a0ade5a9c589eb57cd0def 192.168.133.99:6002@16002 slave 61090aa7cfad982cf7cd8c621201463300bcf28e 0 1697364803454 3 connected
dddef88bf455737ced62b5616a6c2385a378904b 192.168.133.97:6001@16001 myself,master - 0 1697364801000 1 connected 0-5460
3b9eb0521dea131c4804ec425174c632444b61b4 192.168.133.97:6002@16002 slave 7244035eceac38f647904276913ad9d6156613ec 0 1697364805649 5 connected
61090aa7cfad982cf7cd8c621201463300bcf28e 192.168.133.98:6001@16001 master - 0 1697364804000 3 connected 5461-10922
7244035eceac38f647904276913ad9d6156613ec 192.168.133.99:6001@16001 master - 0 1697364805000 5 connected 10923-16383
2、原因分析
造成此异常,通常是以下两种原因:
1)启动 redis-cli时未设置集群模式;
2)开启集群后,redis-cli用普通用户登录无法操作集群数据,需加上-c,采用集群模式登录.
3、解决过程
192.168.133.97:6001> exit
You have new mail in /var/spool/mail/redis
[redis@redis-leo-master ~]$ /opt/redis/bin/redis-cli -h 192.168.133.97 -c -p 6001 -a rcpassword1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.133.97:6001> set k1 v1
-> Redirected to slot [12706] located at 192.168.133.99:6001
OK
192.168.133.99:6001> get k1
"v1"
说明:如上所示,添加-c登录数据库后,成功添加键值k1.
4、数据验证
192.168.133.99:6001> exit
You have new mail in /var/spool/mail/redis
[redis@redis-leo-master ~]$ /opt/redis/bin/redis-cli -h 192.168.133.97 -c -p 6002 -a rcpassword1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.133.97:6002> get k1
-> Redirected to slot [12706] located at 192.168.133.99:6001
"v1"
192.168.133.97:6002> exit
[redis@redis-leo-master ~]$ /opt/redis/bin/redis-cli -h 192.168.133.98 -c -p 6002 -a rcpassword1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.133.98:6002> get k1
-> Redirected to slot [12706] located at 192.168.133.99:6001
"v1"
192.168.133.98:6001> exit
[redis@redis-leo-master ~]$ /opt/redis/bin/redis-cli -h 192.168.133.99 -c -p 6002 -a rcpassword1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.133.99:6002> get k1
-> Redirected to slot [12706] located at 192.168.133.99:6001
"v1"
说明:如上所示,数据在其它节点成功显示.
参考文档:https://blog.csdn.net/MyNAMS/article/details/119940960
标签:6002,133.97,6001,redis,133.99,MOVED,192.168,键值
From: https://blog.51cto.com/u_12991611/7873051