本文内容为 http://redis.io/commands/cluster-slots 的翻译、注解、例子扩充及其它修改。感谢 Redis 作者 Antirez 为开源社区作出的贡献,本文保证最新、最准、最全以表示对其的敬意。欢迎留言纠错、提示更新或支持。
CLUSTER SLOTS

返回当前簇(Cluster)状态的数组响应(Array reply),可以确定哪个簇槽(Slot)对应哪个 Redis 实例(Instance)

Returns Array reply of current cluster state.

CLUSTER SLOTS returns details about which cluster slots map to which Redis instances.

  • Array reply: nested list of slot ranges with IP/Port mappings.
  • 127.0.0.1:7001> cluster slots
    1) 1) (integer) 0
       2) (integer) 4095
       3) 1) "127.0.0.1"
          2) (integer) 7000
       4) 1) "127.0.0.1"
          2) (integer) 7004
    2) 1) (integer) 12288
       2) (integer) 16383
       3) 1) "127.0.0.1"
          2) (integer) 7003
       4) 1) "127.0.0.1"
          2) (integer) 7007
    3) 1) (integer) 4096
       2) (integer) 8191
       3) 1) "127.0.0.1"
          2) (integer) 7001
       4) 1) "127.0.0.1"
          2) (integer) 7005
    4) 1) (integer) 8192
       2) (integer) 12287
       3) 1) "127.0.0.1"
          2) (integer) 7002
       4) 1) "127.0.0.1"
          2) (integer) 7006
  • Nested Result Array

    Each nested result is:
    • Start slot range
    • End slot range
    • Master for slot range represented as nested IP/Port array
    • First replica of master for slot range
    • Second replica
    • ...continues until all replicas for this master are returned.
    Each result includes all active replicas of the master instance for the listed slot range. Failed replicas are not returned.
    The third nested reply is guaranteed to be the IP/Port pair of the master instance for the slot range. All IP/Port pairs after the third nested reply are replicas of the master.
    If a cluster instance has non-contiguous slots (e.g. 1-400,900,1800-6000) then master and replica IP/Port results will be duplicated for each top-level slot range reply.

  • 版本支持

    3.0.0+

    时间复杂度(Time complexity)

    O(N)N 为簇节点的总数。

    O(N) where N is the total number of Cluster nodes