redis - 您如何订阅哨兵并从他们那里接收出版物?

标签 redis jedis

我正在尝试使用发布/订阅实现。在 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/

相关文章:

在 header 中找不到 Spring Boot 安全性 x-auth-token

tomcat - Redis/Jedis - Tomcat 挂起 - - 等待 <5c1a77ba>(一个 org.apache.commons.pool.impl.GenericObjectPool$Latch)

java - 带有对象池的 Jediscluster

java - WRONGTYPE 针对持有错误类型值的键的操作

java - JedisPoolConfig 不可分配给 GenericObjectPoolConfig

go - Golang 中的原子和并发安全 Redis 事务

java - 在 Spring 4 中干燥一个通用的 RedisTemplate

laravel - 如何在共享主机中安装 Redis

python - 无法检查 celery 队列

java - 需要 "increment"中 "jedis"的一些建议