Board logo

标题: Redis 3.0.5 集群的命令、使用、维护(7) [打印本页]

作者: look_w    时间: 2018-12-16 15:46     标题: Redis 3.0.5 集群的命令、使用、维护(7)

cluster setslot <\slot> importing <\node_id>从 node_id 指定的节点中导入 slot 到本节点。
上面的命令居然失效了,日了狗,现在看下这个命令呢?
127.0.0.1:7003> cluster setslot 16383 importing 6f5cd78ee644c1df9756fc11b3595403f51216ccOK127.0.0.1:7003>

将 7002 上的 18383转移到 7003上来,居然成功了。好吧。&#128531;
127.0.0.1:7003> cluster nodes35bdcb51ceeff00f9cc608fa1b4364943c7c07ce 192.168.33.13:7003 myself,master - 0 0 4 connected
[16383-
<-6f5cd78ee644c1df9756fc11b3595403f51216cc]6f5cd78ee644c1df9756fc11b3595403f51216cc 192.168.33.13:7002 master - 0 1448621921706 3 connected 8192-12287 16383

居然显示成这样的,屌屌屌。然而,16383还在 7002上。哎。无法理解。
check 下:
[url=][/url]
[root@web3 7000]# redis-trib.rb check 192.168.33.13:7000...M: 35bdcb51ceeff00f9cc608fa1b4364943c7c07ce 192.168.33.13:7003slots: (0 slots) master2 additional replica(s)...>>> Check for open slots...[WARNING] Node 192.168.33.13:7003 has slots in importing state (16383).[WARNING] The following slots are open: 16383>>> Check slots coverage...[ERR] Not all 16384 slots are covered by nodes.[url=][/url]


它提示集群失败,说正在导入!什么鬼啊。完全搞不懂。跳过吧,看下一个命令:
cluster setslot <\slot> stable取消 slot 的导入(import)或者迁移(migrate)。
这个命令屌啊,还可以反悔啊。赶紧试一试:
127.0.0.1:7003> cluster setslot 16383 stableOK

看下回去了没?
127.0.0.1:7003> cluster nodes35bdcb51ceeff00f9cc608fa1b4364943c7c07ce 192.168.33.13:7003 myself,master - 0 0 4 connected6f5cd78ee644c1df9756fc11b3595403f51216cc 192.168.33.13:7002 master - 0 1448623146511 3 connected 8192-12287 16383

果然回去了,赞赞赞。再 check 下:
[ERR] Nodes don't agree about configuration!>>> Check for open slots...>>> Check slots coverage...[ERR] Not all 16384 slots are covered by nodes.

刚才那个错误消息了。好吧。继续学习其它命令吧。
cluster keyslot <\key>计算键 key 应该被放置在哪个槽上。这个是个蛮不错的功能。有时候很想找一个key在哪个节点。看下能不能用。
[url=][/url]
127.0.0.1:7000> cluster keyslot name(integer) 5798127.0.0.1:7000> get name-> Redirected to slot [5798] located at 192.168.33.13:7001"123"192.168.33.13:7001>[url=][/url]


这个很简单,就是一个运算,之前也讲过: CRC16('name')%16384 = 5798
cluster countkeysinslot <\slot>计算一个slot 包含多少个key。这也是一个很使用的小功能。
试一下:
192.168.33.13:7001> cluster countkeysinslot 5798(integer) 1

由于是测试,所以,slot里数据很少,这里显示1个,估计就是上面的name
cluster getkeysinslot <\slot> <\count>返回 一个 slot 中 count 个 key 的集合。 也是一个蛮实用的功能。
试一下:

127.0.0.1:7000> cluster getkeysinslot 5798 1(empty list or set)
那设置几个值吧:
  [url=][/url]
192.168.33.13:7000> set name1 yangyi-> Redirected to slot [12933] located at 192.168.33.13:7003OK192.168.33.13:7003> set name2 yangyi-> Redirected to slot [742] located at 192.168.33.13:7000OK192.168.33.13:7000> set name3 yangyi-> Redirected to slot [4807] located at 192.168.33.13:7001OK192.168.33.13:7001> set name4 yangyi-> Redirected to slot [8736] located at 192.168.33.13:7002OK192.168.33.13:7002> set name5 yangyi-> Redirected to slot [12801] located at 192.168.33.13:7003OK192.168.33.13:7003> set name6 yangyi-> Redirected to slot [610] located at 192.168.33.13:7000OK192.168.33.13:7000> set name7 yangyi-> Redirected to slot [4675] located at 192.168.33.13:7001OK192.168.33.13:7001>[url=][/url]


好。我们再取一下:
192.168.33.13:7001> cluster getkeysinslot 4675 11) "name7"

cluster slaves <\node-id>返回一个master节点的slaves 列表
192.168.33.13:7001> cluster slaves 7b39b81b5ba94a9f4d96931dd0879cc13dab6f071) "f8c7a3113497d8d828bdb05fec4041b382e5fd0a 192.168.33.13:7005 slave 7b39b81b5ba94a9f4d96931dd0879cc13dab6f07
0 1450671948824 6 connected"

和cluster nodes命令查看的结果是一样的。




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0