I am using the StackExchange.Redis library in C# and have come across an issue related to Redis Cluster and PubSub functionality.
Setup
- Redis Cluster with multiple shards.
- Many subscribers in the system using PubSub.
Problem: I've observed that when I subscribe to messages in a PubSub channel, the clients always consume messages from one specific shard. This results in that particular shard becoming overloaded, even though I have many subscribers distributed in my system.
Understanding: Based on the official Redis documentation, PubSub is designed to work such that you can publish messages to any shard. These messages will then be propagated automatically to all other shards, allowing subscribers to consume messages from any shard.
It seems that StackExchange.Redis is not respecting this behavior.
Questions:
- Is there any configuration within StackExchange.Redis that I might be missing to distribute the PubSub consumption across shards?
- Is this behavior a known limitation of the StackExchange.Redis library when used with a Redis Cluster?
Code Sample
Code for subscribing:
string connectionString = "..."; string channelName = "..."; var connection = await ConnectionMultiplexer.ConnectAsync(connectionString); var channelMessageQueue = connection.GetSubscriber().Subscribe(channelName); channelMessageQueue.OnMessage(message => { // process my message }); Code for sending: await connection.GetDatabase().PublishAsync(channelName, "hello");
Any help or insights would be appreciated!
Источник: https://stackoverflow.com/questions/770 ... -one-shard