为什么哨兵不订阅 sentinelReconnectInstance 中的频道“__sentinel__:hello”

Why don't sentinels subscribe channel "__sentinel__:hello" in sentinelReconnectInstance

在查看Redis的源代码时,我发现当sentinelRedisInstanceSRI_SENTINEL时,sentinelReconnectInstance不会初始化它的link->pc并且不会订阅频道"__sentinel__:hello",如下代码所示。

void sentinelReconnectInstance(sentinelRedisInstance *ri) {
    ...

    if ((ri->flags & (SRI_MASTER|SRI_SLAVE)) && link->pc == NULL) {
    ...
            retval = redisAsyncCommand(link->pc,
                sentinelReceiveHelloMessages, ri, "%s %s",
                sentinelInstanceMapCommand(ri,"SUBSCRIBE"),
                SENTINEL_HELLO_CHANNEL);
    ...


因此,我认为哨兵无法从频道 "__sentinel__:hello" 获得任何消息。

然而,在redis的doc中,它说

Every Sentinel is subscribed to the Pub/Sub channel sentinel:hello of every master and replica, looking for unknown sentinels. When new sentinels are detected, they are added as sentinels of this master.

我认为这意味着所有哨兵实际上都订阅了频道"__sentinel__:hello",但我在redis的源代码中看不到任何对应的实现。

如有错误请指正

sentinelRedisInstance 类型 SRI_MASTER 连接到此哨兵正在监视的主节点,sentinelRedisInstance 类型 SRI_SLAVE 连接到从节点,sentinelRedisInstance类型 SRI_SENTINEL 连接到其他哨兵。

不需要订阅哨兵的频道,哨兵只需要订阅主从节点的频道即可。如果有新的sentinel,它会向master和slave的channel发布hello消息。以便其他哨兵发现他们。