0
votes

I'm using StackExchange.Redis .NET client for Redis (installed on Windows 7). Hostname - 127.0.0.1, port - 6379

Subscriber:

using (var connection = ConnectionMultiplexer.Connect(string.Format("{0}:{1},abortConnect=false,ConnectTimeout=10000", m_HostName, m_Port)))
{
   var sub = connection.GetSubscriber();
   sub.Subscribe("tasks", (channel, value) =>
   {
      // processing
   });
}

Publisher:

using (var connection = ConnectionMultiplexer.Connect(string.Format("{0}:{1},abortConnect=false,ConnectTimeout=10000", m_HostName, m_Port)))
{
   var subscriber = connection.GetSubscriber();
   Logger.Debug(subscriber.IsConnected().ToString());
   subscriber.Publish("tasks", message);
}

In logs I can see that subscriber is connected and there is no exception on this row:

subscriber.Publish("tasks", message); 

But subscriber doesn't catch any message and Redis Desktop Manager shows that DB is empty.

In redis cli the command PUBSUB CHANNELS displays next result, that means that channel exists:

  1. "tasks"
  2. "__Booksleeve_MasterChanged"

Also, I pushed string to DB and it was successfull:

var db = connection.GetDatabase();
db.StringSet("key","message");

Any ideas or suggestions?

1
Publish is not setting anything in database - it is expected (db and pub/sub spaces are mostly distinct, unless you enable keyspace notifications). Are you sure you are starting your subscribed well ahead of publisher? If publisher is sending data before subscriber registers, you won't get notified about previous value (redis pub/sub is update-only, without initial image). - Artur Biesiadowski

1 Answers

1
votes

The connection of your subscriber will be disposed unless you block your client at the end of the using-statement. Therefore your client won't receive any pubsub messages after the using-statement.