我正在尝试获取当前正在监视redis master的所有哨兵的列表。

我知道,如果我有一个哨兵,我可以使用sentinel sentinels mymaster,但是如果我没有哨兵的地址,我该如何获取它们?

最佳答案

没有直接命令从主/从节点获取前哨列表。要获取前哨列表,您需要订阅任何节点的pub / sub(无关紧要的主/从节点)“__ sentinel __:hello”通道,然后等待消息。通过该hello通道传递的消息来自正在侦听该群集的哨兵。如果您解析这些内容,则会获得前哨的地址。消息的格式为:“sentinel_ip,sentinel_port,sentinel_runid,sentinel_current_epoch,master_name,master_ip,master_port,master_config_epoch”(例如127.0.0.1,26380,07fabf3cbac43bcc955588b1023f95498b58f8f2,16,0.1。,mymaster1212)。有关哨兵的详细信息,请参见:https://redis.io/topics/sentinel#sentinels-and-slaves-auto-discovery。如果您需要更多了解哨兵的工作原理,请查看https://github.com/antirez/redis/blob/unstable/src/server.c

10-08 12:58