Support subscriptions against cluster slave nodes #3480
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
SUBSCRIBE
(and its sibling variant commands) establish connections only to masters, regardless of theReadOnly
option specified in client options.This PR allows go-redis to respect the
ReadOnly
option for subscriptions in the pubsub client, by preferring slave nodes for new connections. Note that in both global and sharded pubsub modes, messages are replicated to slaves by Redis.Note that
newConn
in the pubsub client is only used for creating connections for long-lived subscriptions, so it does not need to consider any per-command R/W-family properties as in the case for commands outside of the pubsub client.I added a new unit test case for both global and sharded subscriptions with
ReadOnly
set to true, with an additional assertion on the value ofpubsub{shard}_channels
as returned byINFO
to additionally verify that the subscription is served only by slave nodes.