CLUSTER ADDSLOTS slot [slot ...]

Available since 3.0.0. 从3.0.0开始可用
Time complexity: O(N) where N is the total number of hash slot arguments
时间复杂度:O(N) N是总的哈希槽数参数

This command is useful in order to modify a node's view of the cluster configuration. 
Specifically it assigns a set of hash slots to the node receiving the command. If the command is successful, 
the node will map the specified hash slots to itself, and will start broadcasting the new configuration.
这个命令的作用是修改集群配置的一个节点的视图。
明确的分配一组哈希槽到接收这个命令的节点,如果命令是成功的,这个接收命令的节点会映射指定的哈希槽到它自己,然后会广播这个新的配置

However note that:
1,The command only works if all the specified slots are, from the point of view of the node receiving the command, currently not assigned. 
A node will refuse to take ownership for slots that already belong to some other node (including itself).
2,The command fails if the same slot is specified multiple times.
如果相同的槽被多次指定命令就会报错
3,As a side effect of the command execution, if a slot among the ones specified as argument is set as importing, 
this state gets cleared once the node assigns the (previously unbound) slot to itself.

命令执行的副作用,如果指定为参数指定的一个槽被设置为导入,那么这个状态在节点将(以前未绑定的)槽分配给自身时就会被清除。

然而注意:
1,这个命令仅仅工作在如果指定的槽是,从收到命令的节点的视点看,当前尚未分配的槽,
一个节点会拒绝所有权已经属于其他节点的槽(包括他自己)
A,执行CLUSTER ADDSLOTS命令的这个节点是给自己分配槽,并且这个槽要是尚未分配的,如果已经分配过的槽,会报错,即使这个槽当前属于它自己也会报错

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504252798782 12 connected 10923-16383
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 myself,master - 0 0 10 connected 5462-10922
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504252799282 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 master - 0 1504252798782 7 connected 0 2-5460

这里可以看到槽号1是属于192.168.4.71:7008节点,我们现在把这个槽分配给192.168.4.70:7004

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster addslots 1
(error) ERR Slot 1 is already busy

槽2目前属于192.168.4.70:7004,那么这个槽还可以再次分配给192.168.4.70:7004?

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster addslots 2
(error) ERR Slot 2 is already busy

B,已经分配的槽需要使用delslots删除之后才可以再次使用addslots

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster delslots 2
OK

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504253092265 12 connected 10923-16383
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504253092766 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 myself,master - 0 0 7 connected 0 3-5460
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 master - 0 1504253092767 10 connected 5462-10922

这里可以看到192.168.4.70:7004删除了槽2

再次使用cluster addslots命令把槽2加入到192.168.4.70 -p 7004

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster addslots 2
OK
[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504253172912 12 connected 10923-16383
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504253174915 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 myself,master - 0 0 7 connected 0 2-5460
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 master - 0 1504253174915 10 connected 5462-10922
[root@redis1 ~]#

再次测试:

从192.168.4.70:7005节点删除槽2,3,4,5

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504254313199 12 connected 10923-16383
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 myself,master - 0 0 10 connected 2-5 5462-10922
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504254313700 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 master - 0 1504254313700 7 connected 0 6-5460

redis-cli -h 192.168.4.70 -p 7005 -c cluster delslots 2 3 4 5

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster delslots 2 3 4 5
OK
[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504254363385 12 connected 10923-16383
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 myself,master - 0 0 10 connected 5462-10922
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504254361381 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 master - 0 1504254363385 7 connected 0 6-5460

在192.168.4.70:7004中加入这4个槽

redis-cli -h 192.168.4.70 -p 7004 -c cluster addslots 2 3 4 5

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504254421992 12 connected 10923-16383
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 myself,master - 0 0 10 connected 5462-10922
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504254421491 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 master - 0 1504254422994 7 connected 0 6-5460

从这里看到2,3,4,5已经从192.168.4.70:7005中去除了

redis-cli -h 192.168.4.70 -p 7004 -c cluster nodes|grep master

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504254486505 12 connected 10923-16383
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504254487108 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 myself,master - 0 0 7 connected 0 6-5460
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 master - 0 1504254488009 10 connected 2-5 5462-10922

但是在192.168.4.70:7004中看到这个2,3,4,5还在192.168.4.70:7005,这个我猜测是slot状态刷新的慢

redis-cli -h 192.168.4.70 -p 7004 -c cluster delslots 2 3 4 5
redis-cli -h 192.168.4.70 -p 7004 -c cluster addslots 2 3 4 5

我们手动在192.168.4.70 -p 7004执行这2条命令
[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster delslots 2 3 4 5
redis-cli -h 192.168.4.70 -p 7004 -c cluster addslots 2 3 4 5OK
[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster addslots 2 3 4 5
OK
[root@redis1 ~]# 
[root@redis1 ~]# 
[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504254598730 12 connected 10923-16383
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504254600731 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 myself,master - 0 0 7 connected 0 2-5460
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 master - 0 1504254600230 10 connected 5462-10922

看到192.168.4.70:7005也直接刷新了

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster nodes|grep master 
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504254645897 12 connected 10923-16383
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 myself,master - 0 0 10 connected 5462-10922
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504254644395 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 master - 0 1504254645395 7 connected 0 2-5460

使用redis客户端命令行的方式迁移slot:

查看当前的集群的master节点
[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504254853974 12 connected 10923-16383
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 myself,master - 0 0 10 connected 5462-10922
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504254854475 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 master - 0 1504254852972 7 connected 0 2-5460

cluster setslot slot_num migrating target_node_id

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster setslot 5462 migrating 48c261163414d244d65fb9a70e09de166440da31
OK

cluster setslot slot_num importing source_node_id

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7004 -c cluster setslot 5462 importing b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f
OK

这里是准备迁移5462到48c261163414d244d65fb9a70e09de166440da31:

[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504254934796 12 connected 10923-16383
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 myself,master - 0 0 10 connected 5462-10922 [5462->-48c261163414d244d65fb9a70e09de166440da31]
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504254933793 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 master - 0 1504254933793 7 connected 0 2-5460

确认开始迁移操作:
[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster setslot 5462 node 48c261163414d244d65fb9a70e09de166440da31 
OK

查看迁移结果:
[root@redis1 ~]# redis-cli -h 192.168.4.70 -p 7005 -c cluster nodes|grep master
b4a9a578069a3b2a413fcb4125d17c8768b13359 192.168.4.70:7006 master - 0 1504255395244 12 connected 10923-16383
b23bfc9ac1fdd4bfb9c799f7985622f54338cb0f 192.168.4.70:7005 myself,master - 0 0 10 connected 5463-10922
631bff889fbb5600febb896d075eeca5a2cd7322 192.168.4.71:7008 master - 0 1504255394744 11 connected 1 5461
48c261163414d244d65fb9a70e09de166440da31 192.168.4.70:7004 master - 0 1504255394744 7 connected 0 2-5460 5462

Example
For example the following command assigns slots 1 2 3 to the node receiving the command:
> CLUSTER ADDSLOTS 1 2 3
OK

However trying to execute it again results into an error since the slots are already assigned:
> CLUSTER ADDSLOTS 1 2 3
ERR Slot 1 is already busy

Usage in Redis Cluster
This command only works in cluster mode and is useful in the following Redis Cluster operations:
To create a new cluster ADDSLOTS is used in order to initially setup master nodes splitting the available hash slots among them.
In order to fix a broken cluster where certain slots are unassigned.
Information about slots propagation and warnings
Note that once a node assigns a set of slots to itself, it will start propagating this information in heartbeat packet headers. However the other nodes will accept the information only if they have the slot as not already bound with another node, or if the configuration epoch of the node advertising the new hash slot, is greater than the node currently listed in the table.
This means that this command should be used with care only by applications orchestrating Redis Cluster, like redis-trib, and the command if used out of the right context can leave the cluster in a wrong state or cause data loss.
Return value
Simple string reply: OK if the command was successful. Otherwise an error is returned.

redis_cluster命令官方文档翻译及实践相关推荐

  1. [iOS]Advanced Memory Management Programming Guide 高级内存管理编程指南(官方文档翻译)

    Advanced Memory Management Programming Guide - 高级内存管理编程指南(官方文档翻译) 版权声明:本文为博主原创翻译,如需转载请注明出处. 新博客文章地址: ...

  2. Ionic Framework 5官方文档翻译

    Ionic Framework 5官方文档翻译 入门 Ionic Framework 5特点 Ionic Framework是什么? 核心概念 构建你的第一个应用 先进的Web应用 浏览器支持 版本控 ...

  3. 欢迎参与 KubeVela 官方文档翻译活动

    来源 | 阿里巴巴云原生公众号 背景 KubeVela v1.0 启用了新的官网架构和文档维护方式,新增功能包括文档版本化控制.i18n 国际化以及自动化流程.但目前 KubeVela 官方文档只有英 ...

  4. 【KubeVela 官方文档翻译】,欢迎大家踊跃参与

    简介:KubeVela v1.0 启用了新的官网架构和文档维护方式,新增功能包括文档版本化控制.i18n 国际化以及自动化流程.但目前 KubeVela 官方文档只有英文版,这提高了学习和使用 Kub ...

  5. db4o_8.0对象数据库官方文档翻译_学习笔记三

    紧接上篇:db4o_8.0对象数据库官方文档翻译_学习笔记二 3. Object Manager Enterprise Overview(OME视图)即OME插件的使用 If you did not  ...

  6. Jess 7.2p2——Java平台规则引擎官方文档翻译1

    Jess 7.2p2--Java平台规则引擎官方文档翻译1 本博客转载自本体小本营. 1.入门 1.1.需求 在使用Jess前请先确认JVM是否正确安装并能正常工作. 使用JessDE集成开发环境,你 ...

  7. Vue3官方文档翻译之Reactivity Fundamentals

    引言 突然不知道这章写了啥, 感觉内容有点干, 顾着翻译去了, 没有吸收消化. 还是总结下, 主要是就是响应式的对象如何和template结合的, 响应式对象是通过JavaScript的代理对象实现的 ...

  8. About HTTP Live Streaming官方文档翻译 [iOS]

    新博客地址:About HTTP Live Streaming官方文档翻译 [iOS] 版权声明:本文为博主原创翻译,如需转载请注明出处. 苹果源文档地址 - 点击这里 About HTTP Live ...

  9. 【iOS官方文档翻译】iOS蓝牙的基本概念

    之前写了[iOS官方文档翻译]iOS的蓝牙连接.数据接收及发送一文,介绍了怎样进行蓝牙通讯,但是很多基本概念没有进行解释,看起来可能有点吃力,所以现在再翻译一篇苹果对官方蓝牙4.0一些基本概念介绍的文 ...

最新文章

  1. mysql是面向对象的语言吗_php一种面向对象的语言,那么什么是面向对象呢?
  2. Linux08--Shell程序设计03 shell script
  3. vue-cli安装教程
  4. 听了一堂《**学院》的课,我也是醉了
  5. Python之数据分析(Numpy中读取与保存数据文件、将数据文件制成K线图)
  6. java 自定义异常实例分析_Java自定义异常类的实例详解
  7. 翻译:通过使用终端(iTerm2&Oh my ZSH)来提高您的生产率
  8. 一键解决局域网共享(批处理)
  9. Word批量打印软件/工具
  10. 网络安全工程师面试题汇总
  11. php短信接口怎么用,php短信接口接入详细过程
  12. 【华人学者风采】于非 加拿大卡尔顿大学
  13. 计算机本地连接怎么找不到了,电脑本地连接不见了该怎么办
  14. 丧心病狂的Monkey测试
  15. Illegal character: U+00A0
  16. Python个人常见语法问题
  17. mysql全文索引与停止词
  18. 字节跳动梁汝波:管理者过于依靠规则会使组织僵化 |王兴:反垄断无损美团竞争优势...
  19. apmserv 5.2.6 升级php,Windows + APMServ5.2.6/PHP5以上
  20. pdfjs 浏览器打印字体模糊问题

热门文章

  1. 常见的8种用户需求评估方法
  2. uniapp连接佳博打印机实现蓝牙打印票据功能
  3. 工作十年以后,你们悟出了什么职场道理?
  4. FPGA-I2C 开发介绍
  5. GeoGebra画傅里叶级数(三角函数积分 or 复变函数积分)
  6. 字节跳动的产品与岗位
  7. 飞鸽传输IPMsg协议+翻译
  8. *crossed matchingpku 1692
  9. Windows自动隐藏任务栏bat脚本
  10. wamp5 Apache启动失败的解决方法