How to PUB/SUB sentinel

Skip to first unread message

Armache Antoni

Apr 5, 2020, 12:39:51 PM4/5/20
to lettuce-redis-client-users
Hi gyus,

I would like to susbribe on the (master sentinel) in order to receive events and message when master dies such as:

- connection down
- connection up
- switch to new master

i have the following code but when i stop master, i am not receiving events or message could someone show me what is wrong in my code:


+----+  +----+  +----+            
| M1 |  | R2 |  | R3 |
| S1 |--| S2 |--| S3 |  
+----+  +----+  +----+           


// Lettuce
static public RedisClient redisClient;
static public RedisClient sentinelClient;
static public RedisAsyncCommands<String, String> asyncCommands = null;
static public StatefulRedisMasterSlaveConnection<String, String> redisConnection;
// Create Redis-URI
RedisURI redisUri = RedisURI.builder().withSentinel("", 26379)
                    .withSentinel("", 26379).withSentinel("", 26379)
// Create Sentinel-Client
sentinelClient = RedisClient.create(redisUri);
// Create Redis-Client
            redisClient = RedisClient.create();
                    // .timeoutOptions(new TimeoutOptions())
                     * DEFAULT: Accept commands when auto-reconnect is enabled, reject commands when
                     * auto-reconnect is disabled. ACCEPT_COMMANDS: Accept commands in disconnected
                     * state. REJECT_COMMANDS: Reject commands in disconnected state.
// Create Redis-Connection
            redisConnection = MasterSlave.connect(redisClient, new Utf8StringCodec(), redisUri);
             asyncCommands = redisConnection.async();
//The listener which is not working!!!!!!
    public static void addSentinelListennerChannel() {
        if (sentinelClient == null)

        // Subscribe: Sentinel -> check failover
    RedisPubSubAdapter<String, String> listener2 = new RedisPubSubAdapter<String, String>() {
            public void message(String channel, String message) {
                if (channel.equals("+switch-master")) {
          "sentinel MASTER CHANGED");
                if (channel.equals("+sdown")) {
          "sentinel MASTER SDOWN");
                if (channel.equals("+odown")) {
          "sentinel MASTER ODOWN");
        StatefulRedisPubSubConnection<String, String> pubsubConn2 = sentinelClient.connectPubSub();
        RedisPubSubAsyncCommands<String, String> async2 = pubsubConn2.async();


Armache Antoni

Apr 5, 2020, 6:19:45 PM4/5/20
to lettuce-redis-client-users
Found the solution on own..... no need to bother guys.....

You received this message because you are subscribed to the Google Groups "lettuce-redis-client-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Jun 1, 2020, 6:22:56 PM6/1/20
to lettuce-redis-client-users
Can you please share the solution here as well
To unsubscribe from this group and stop receiving emails from it, send an email to
Reply all
Reply to author
0 new messages