StackExchange.Redis Basics

Example

Once connected you can publish messages by calling the ISubscriber.Publish method:

// grab an instance of an ISubscriber
var subscriber = connection.GetSubscriber();

// publish a message to the 'chat' channel
subscriber.Publish("chat", "This is a message")

Consumers can subscribe to the channel using the ISubscriber.Subscribe method. Messages sent by the publisher will be handled by the handler passed to this method.

// grab an instance of an ISubscriber
var subscriber = connection.GetSubscriber();

// subscribe to a messages over the 'chat' channel
subscriber.Subscribe("chat", (channel, message) => {
    // do something with the message
    Console.WriteLine((string)message);
});