我正在尝试使用发布/订阅实现。在 Jedis 上获取有关 master 下线的信息,但我不确定如何订阅 Sentinel channel 。
我的发布者类:
public Publisher(Jedis publisherJedis, String channels, String clusterName) {
this.publisherJedis = publisherJedis;
this.channels = channels;
this.clusterName = clusterName;
}
public void start() {
log.info("publishing on channel +odown");
try {
while(true) {
if(JedisPoolFactory.getMasterDown(clusterName)) {
publisherJedis.publish("+odown", "master down, master down");
}
}
} catch(Exception ex) {
log.error("failure with end of stream catching.", ex);
}
}
我必须将我的哨兵注册为发布者,我需要做的就是在每次发生主故障转移时解码消息。我该如何订阅 sentinel channel ?
最佳答案
正如 antirez 所说,您可以使用普通 Jedis 实例连接到 sentinel,并订阅 channel 。它与 Redis 的发布/订阅完全相同。
关于redis - 您如何订阅哨兵并从他们那里接收出版物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31190419/