【发布时间】:2020-10-22 12:25:13
【问题描述】:
查看Redis的源代码,我发现当sentinelRedisInstance是SRI_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 中,它说
每个 Sentinel 都订阅了 Pub/Sub 频道 sentinel:hello 每个 master 和 replica,寻找未知的 sentinel。当检测到新的哨兵时,它们会被添加为此主服务器的哨兵。
我认为这意味着所有的哨兵实际上都订阅了频道"__sentinel__:hello",但是我在redis的源代码中看不到任何对应的实现。
【问题讨论】:
标签: redis redis-sentinel