为什么哨兵不在sentinelReconnectInstance

时间:2020-10-22 12:25:13

标签: redis redis-sentinel

查看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中,它表示为

每个哨兵都订阅了每个主副本和副本的发布/订阅频道哨兵:hello,以查找未知的哨兵。当检测到新的标记时,会将它们添加为该主标记的标记。

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

1 个答案:

答案 0 :(得分:1)

如果我错了,请纠正我。

类型为sentinelRedisInstance

SRI_MASTER连接到该哨兵正在监视的主节点,类型为sentinelRedisInstance的{​​{1}}连接到从节点,并且类型为SRI_SLAVE sentinelRedisInstance连接到其他标记。

不需要订阅哨兵的频道,相反,哨兵只需要订阅主节点和从节点的频道。如果有新的标记,它将向主机和从机的通道发布问候消息。这样其他哨兵就会发现它们。