I’m trying to write a straightforward .Net app that will subscribe to a cluster of Redis nodes, to receive change notifications.
The cluster configuration is the following:
➜ redis-cli -h 10.0.255.86
10.0.255.86:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:3
cluster_size:3
cluster_current_epoch:3
cluster_my_epoch:1
cluster_stats_messages_ping_sent:56121935
cluster_stats_messages_pong_sent:56144253
cluster_stats_messages_fail_sent:26
cluster_stats_messages_sent:112266214
cluster_stats_messages_ping_received:56144251
cluster_stats_messages_pong_received:56121914
cluster_stats_messages_meet_received:2
cluster_stats_messages_fail_received:16
cluster_stats_messages_received:112266183
total_cluster_links_buffer_limit_exceeded:0
10.0.255.86:6379> cluster nodes
d8c89d2e48623dc09840ec0f819c6b1f66bacfd7 10.0.255.86:6379@16379 myself,master - 0 1688093343000 1 connected 0-5460
22ccfb5a7aa80e5946cdca37a086b65cd56147c2 10.0.255.88:6379@16379 master - 0 1718880916241 3 connected 10923-16383
4d5f1e2f4eef90d818335cfef0ecb8763c065b2d 10.0.255.87:6379@16379 master - 0 1718880917304 2 connected 5461-10922
each node is configured with: notify-keyspace-events KEA
10.0.255.86:6379> config get notify-keyspace-events
1) "notify-keyspace-events"
2) "AKE"
10.0.255.86:6379>
If I connect redis-cli
to all nodes and subscribe with PSUBSCRIBE __key*__:*
I will receive all the changes that happen on each of them. However, when I run the app it will output Subscribed to Redis endpoint 10.0.255.86:6379
and will only receive messages from 10.0.255.86
.
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var redis = ConnectionMultiplexer.Connect("10.0.255.86:6379, 10.0.255.87:6379, 10.0.255.88:6379");
var subscriber = redis.GetSubscriber();
RedisChannel topic = "__key*__:*";
subscriber.Subscribe(topic, (channel, value) =>
{
System.Console.WriteLine("Key change notification received. Channel: {0}, Value: {1}", channel, value);
});
var endpoint = subscriber.SubscribedEndpoint(topic);
System.Console.WriteLine("Subscribed to Redis endpoint {0}", endpoint);
System.Console.ReadLine();
}
}
}
Can anybody tell if there is a way to subscribe to receive the notifications from all the nodes? If the ConnectionMultiplexer
supports it, then what do I do wrong?
I tried using a separate multiplexer per node but those that connect to 10.0.255.87
and 10.0.255.88
still get the messages from 10.0.255.86
only. I guess the ConnectionMultiplexer
gets the whole list of nodes after connects and always subscribes for the first one.
I would appreciate any help!
Thanks!