BB.Caching.Redis.PubSub.PubSubSingleton.Subscribe C# (CSharp) Method

Subscribe() public method

Creates a subscription to a channel.
public Subscribe ( string channel, Action subscriptionCallback ) : void
channel string /// The channel of the subscription. ///
subscriptionCallback Action /// The callback method. ///
return void
            public void Subscribe(string channel, Action<string> subscriptionCallback)
            {
                // Check to make sure we're not re-creating an existing subscription first.
                if (this.ActiveKeylessSubscriptions.ContainsKey(channel))
                {
                    throw new ChannelAlreadySubscribedException(
                        string.Format("subscription to channel {0} already exists", channel));
                }

                // Let's add this subscription to our cache. We'll need to remember it so that we can re-subscribe
                // if we lose our connection at any point.
                this.ActiveKeylessSubscriptions[channel] = subscriptionCallback;
                this.Subscriptions.Subscribe(
                    channel,
                    (sameAsChannel, data) =>
                    {
                        string value = Encoding.UTF8.GetString(data);
                        subscriptionCallback(value);
                    });
            }

Same methods

PubSub.PubSubSingleton::Subscribe ( string channel, string key, Action subscriptionCallback ) : void