zhaoguihuadediannao:src zhaogh$ ./redis-trib.rb reshard 127.0.0.1:9003 然后输出了很多信息,很多数值和ID都可以从这段信息中找到。
How many slots do you want to move (from 1 to 16384)? 5461
会问你要移动多少个哈希槽,我们把 9003 上的所有哈希槽都移走,5461 这个数字可以从终端上看到,或许你的实际情况不是这个数字。
What is the receiving node ID? 4d2e0a8360795ce7ce8381c68746034aeba3c9b9 然后问你你要把这些哈希槽移到哪儿去,我指定了 9001 的节点 ID。
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots. Type 'done' once you entered all the source nodes IDs.
Source node #1:78ec1fd6647b79627d7c29bb2b22d04a4a6c43b3 Source node #2:done
之后,redis 列出了重新分片计划,最后问你
Do you want to proceed with the proposed reshard plan (yes/no)? yes
执行完成后,我们看看 9003 上还有没有 key:
zhaoguihuadediannao:src zhaogh$ ./redis-cli -p 9003 127.0.0.1:9003> keys * (empty list or set) 127.0.0.1:9003>
再看看 9001 上是不是有这个 key 了
zhaoguihuadediannao:src zhaogh$ ./redis-cli -p 9001 127.0.0.1:9001> keys * 1) \127.0.0.1:9001> 没错,果然转移过来了。
最后我们试试能不能把 9003 删除:
zhaoguihuadediannao:src zhaogh$ ./redis-trib.rb del-node 127.0.0.1:9001 '78ec1fd6647b79627d7c29bb2b22d04a4a6c43b3'
>>> Removing node 78ec1fd6647b79627d7c29bb2b22d04a4a6c43b3 from cluster 127.0.0.1:9001
Connecting to node 127.0.0.1:9001: OK Connecting to node 127.0.0.1:9002: OK
Connecting to node 127.0.0.1:9003: OK
>>> Sending CLUSTER FORGET messages to the cluster... >>> SHUTDOWN the node.
zhaoguihuadediannao:src zhaogh$ ./redis-cli -p 9003
Could not connect to Redis at 127.0.0.1:9003: Connection refused not connected> 非常好,it’s very good.