You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running github.com/go-redis/redis/v8 at the moment, I have a ClusterClient configured to talk to a Redis cluster (AWS ElastiCache in this case) and it is configured with ReadOnly: true as in general I can retrieve most of the data from replicas.
However, certain read-only commands (such as GET) need to execute against the primary node holding the key to ensure strong consistency semantics in the application. This is particularly problematic when using Pipelines or Transactions.
What's the best way to ensure such behavior. I've explored a few options, but each have downsides:
Keep 2 ClusterClient instances, one with ReadOnly: true, the other with ReadOnly: false. This seems like it would double the number of connections and handshake/topology commands against the cluster
Use MasterForKey to get the primary node. However, this is somewhat cumbersome to use, and may not work correctly with Pipelined/TxPipelined as it requires knowing the key ahead of time and bypasses the ClusterClient's behavior of grouping the commands by hash slot.
Include some innocuous non-readonly command in the pipeline (e.g. SET foo bar XX) to skip the read-only path that allows using replicas. This feels like a hack and won't be obvious to future devs without additional comments/explanation.
UseMaster here would just return itself if ReadOnly=false, but if ReadOnly=true it would return an instance that suppresses the slotReadOnlyNode selection, e.g. in
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Running
github.com/go-redis/redis/v8
at the moment, I have a ClusterClient configured to talk to a Redis cluster (AWS ElastiCache in this case) and it is configured withReadOnly: true
as in general I can retrieve most of the data from replicas.However, certain read-only commands (such as
GET
) need to execute against the primary node holding the key to ensure strong consistency semantics in the application. This is particularly problematic when using Pipelines or Transactions.What's the best way to ensure such behavior. I've explored a few options, but each have downsides:
ClusterClient
instances, one withReadOnly: true
, the other withReadOnly: false
. This seems like it would double the number of connections and handshake/topology commands against the clusterMasterForKey
to get the primary node. However, this is somewhat cumbersome to use, and may not work correctly withPipelined/TxPipelined
as it requires knowing the key ahead of time and bypasses the ClusterClient's behavior of grouping the commands by hash slot.SET foo bar XX
) to skip the read-only path that allows using replicas. This feels like a hack and won't be obvious to future devs without additional comments/explanation.Ideally I'd want something like
UseMaster
here would just return itself ifReadOnly=false
, but ifReadOnly=true
it would return an instance that suppresses the slotReadOnlyNode selection, e.g. ingo-redis/cluster.go
Lines 1799 to 1802 in 8b2bcd5
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions