Eitan
Eitan

Reputation: 1386

Call unsubscribe with REDIS

I am using REDIS.

I need to use unsubscribe in Redis. I am using ServiceStack for C#: https://github.com/ServiceStack/ServiceStack.Redis

I copied the code of: http://docs.servicestack.net/redis-client/redis-pubsub

When doing subscribe there is infinite lock, so what I did is doing subscribe in thread.

I can do unsubscribe, but not with unsubscribe method. This is done fine with:

myThread.abort();
... // + sending just a publish message.

but I need to do that with unsubscribe method.

 subscription.UnSubscribeFromAllChannels(); // ****Not like that***

// Not wanting doing like above as the example on the second link, 
// but need to do as following:
     subsciption.unsubscribe(new string[] {"MyChannel"});
unfortunely, the above just doesn't work at all (no unsubscribe).

I didn't see any example on web and I need to call unsubscribe not as same as the second link example ,which checked out:

if (++messagesReceived == PublishMessageCount) etc.)

How can I do unsubscribe using the method subsciption.unsubscribe as I described in this post?

Upvotes: 0

Views: 1794

Answers (1)

mythz
mythz

Reputation: 143359

The Subscribe* API's will block the current thread. Once subscribed the callbacks execute messages on the same thread as the subscription. You'll also need to call unsubscribe with the same subscription on the same thread.

Rather than using Redis Pub/Sub API's directly it's easier to just use RedisPubSubServer which manages the subscription in a background thread for you.

Upvotes: 1

Related Questions