我正在使用 REDIS。
我需要在 Redis 中使用取消订阅。 我正在为 C# 使用 ServiceStack:https://github.com/ServiceStack/ServiceStack.Redis
我复制了以下代码:http://docs.servicestack.net/redis-client/redis-pubsub
订阅的时候有无限锁,所以我是在线程里订阅。
我可以取消订阅,但不能使用取消订阅方法。这可以很好地完成:
myThread.abort();
... // + sending just a publish message.
但我需要使用取消订阅方法来做到这一点。
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).
我没有在网上看到任何示例,我需要调用取消订阅,这与第二个链接示例不同,已 checkout :
if (++messagesReceived == PublishMessageCount) etc.)
如何使用本文中描述的方法 subsciption.unsubscribe 取消订阅?
最佳答案
Subscribe* API 将阻塞当前线程。订阅后,回调在与订阅相同的线程上执行消息。您还需要在同一线程上使用同一订阅调用取消订阅。
它不是直接使用 Redis Pub/Sub API,而是 easier to just use RedisPubSubServer它在后台线程中为您管理订阅。
关于c# - 使用 REDIS 调用取消订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32210629/