redis在添加键值时报错"(error) MOVED...."
  COAWCwhiWpsR 2023年11月02日 24 0
问题描述: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
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  TZ5i7OqYsozK   2023年12月12日   43   0   0 IPredisIPredis
  xaeiTka4h8LY   2024年04月26日   48   0   0 yumredis
  xaeiTka4h8LY   2024年04月26日   45   0   0 centoslinuxredis
COAWCwhiWpsR