利用docker轻松搭建Redis-Cluster集群环境( 三 )

在这里可以很清晰明了的看到有3个master节点和3个slave节点的IP地址和端口信息 。
redis-cluster连接测试redis-cluster搭建好之后,随意连接一个redis节点,无论是主节点还是从节点都可以,在这里选择连接一个从节点 。
192.168.112.136:8001> cluster nodes0956927ee74737d5ff91a1885e77f94d531dab76 192.168.112.136:8002@18002 master - 0 1603265855374 2 connected 5461-1092296d2cb55f163ecc13a714ba01d90348c1c3ad02f 192.168.112.136:8004@18004 slave c9e549f4d04d4466d2550d1e027412304099b1f2 0 1603265856080 4 connectedaa7c2f6173904973f041b35efc5200359188eb0f 192.168.112.136:8006@18006 slave d6321788b2717b4142390c158ba70ca758f70964 0 1603265855575 6 connected8a771c26a95e82d9a6818e372d7c0226937670ac 192.168.112.136:8005@18005 slave 0956927ee74737d5ff91a1885e77f94d531dab76 0 1603265855575 5 connectedd6321788b2717b4142390c158ba70ca758f70964 192.168.112.136:8003@18003 master - 0 1603265856382 3 connected 10923-16383c9e549f4d04d4466d2550d1e027412304099b1f2 192.168.112.136:8001@18001 myself,master - 0 1603265855000 1 connected 0-5460root@f4c971ce2d84:~# redis-cli -c -a 1234 -h 192.168.112.136 -p 8004Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.192.168.112.136:8004> 192.168.112.136:8004> set 5 test5-> Redirected to slot [9974] located at 192.168.112.136:8002192.168.112.136:8002> 仔细看一下,当在slave节点写入数据时,redis-cluster将你的写请求重定向到另一个master节点了,至于原因,在这里就不说了,下次再讲解redis-cluster集群原理篇再细讲 。
测试查询
root@f4c971ce2d84:~# redis-cli -c -a 1234 -h 192.168.112.136 -p 8006Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.192.168.112.136:8006> 192.168.112.136:8006> get 5-> Redirected to slot [9974] located at 192.168.112.136:8002"test5"192.168.112.136:8002>在这里查询也被路由重定向了 。
致谢1.如果您喜欢,请在评论区评论+点赞+转发
2.如果您很喜欢,请关注本头条号




推荐阅读