-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
PSubscribe is subscribing on one slot, one node. Pattern could not be predicted beforehand, thus subscription should be done for all nodes.
Expected Behavior
Since PSubscribe is creating subscription based on pattern then channel should be ready to receive changes from any cluster node.
Current Behavior
In cluster mode client attempts to calculate node based on pattern string. It will never work as pattern characters *? will be replaced with different key value.
https://github.com/redis/go-redis/blob/master/osscluster.go#L1663
Possible Solution
- Cluster mode client should create subscription for all master nodes
- Aggregate all connection output into 1 channel
- On cluster scale and/or slot resharding connection should be updated. In the end channel output should hide all cluster implementation details.
Steps to Reproduce
- Create a cluster.
- Turn on key change notifications. Send
config set notify-keyspace-events KEAfor every node - Create PubSub channel by pattern
chan := client.PSubscribe(context.TODO(), __keyspace@0__:MyKeyPattern*).Channel()
- set data
Set MyKeyPattern123 123
Set MyKeyPattern456 456
It is expected that keys will be populated in different slots. It depends on your cluster setup
Context (Environment)
Application tries to reduce amount of traffic to DB. It triggers value update only on specific key pattern change only if such key is added/removed in DB. Solution works in regular single node approach, but fails in cluster mode.