Redis topology and Pub/Sub

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Redis topology and Pub/Sub

Standalone topology

Both publish and subscribe work correctly.

Master/Replica topology

  • Within the same server (Master/Replica), messages are propagated and a return value is received.
    > publish ch01 Msg
    (integer) 1
  • Redis Master -> Replica: the publish message is propagated, but the return value is not delivered.
    > publish ch01 Msg
    (integer) 0
  • Replica -> Master, Replica_1 -> Replica_2: the publish message is not propagated.

[Note] Java Lettuce/Spring does not support the Master/Replica topology.
            [as of Spring Boot 3.1.7, Lettuce 6.2.7, Redis 7.2.3]

  • Java Lettuce MasterReplica (StatefulRedisMasterReplicaConnection) does not support Pub/Sub. That connection has no publish or subscribe methods.
  • Java Spring RedisStaticMasterReplicaConfiguration does not support Pub/Sub.
    An exception is thrown saying it is not supported, with the following message.
    "Pub/Sub connections not supported with Master/Replica configurations"
    Java Source: /org/springframework/data/redis/connection/lettuce/
                StaticMasterReplicaConnectionProvider.java

    Related GitHub issue January 30, 2020
    Mark Paluch (Lettuce developer) commented

    Using Master/Replica does not work with Pub/Sub.
    First, Lettuce has no Pub/Sub implementation for Master/Replica.
    The second reason is that Redis Standalone or Replica does not propagate Pub/Sub messages across nodes. That is available only in Redis Cluster.
    Therefore a message sent on one node cannot be received on another node.

    Using Master/Replica isn't going to work with Pub/Sub.
    First, there is no Pub/Sub implementation in Lettuce for Master/Replica.
    The second reason is that Redis Standalone or Replica does not propagate Pub/Sub messages across nodes.
    That's only available in Redis Cluster. So messages sent on one node cannot be received on a different node. We should improve at least the exception and our docs to indicate that Pub/Sub isn't supported.

Sentinel topology

When implemented with Java Spring, both Auto Config and Manual Config (ReadFrom setting) handle Publish/Subscribe correctly.
Mark Paluch (Lettuce developer) mentioned "(without setting ReadFrom)", as if Pub/Sub would not work when ReadFrom is set, but it works well.
Processing is all done on the master. The application connects Pub/Sub only to the master.

Cluster topology

When you publish in a cluster, the message is sent to all nodes including replicas. So a replica can subscribe to a message published on a master.  You can also publish from a replica, not only from a master. A replica can subscribe to a message published from another replica. 
If Pub/Sub is important to you, use Redis Cluster.


Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< Pub/Sub Intro Redis Config & Pub/Sub Pub/Sub Internal >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.