c# - 使用 REDIS 调用取消订阅

标签 c# redis

我正在使用 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/

相关文章:

具有多个返回 string 和 int 的 C# 类

c# - 我想清除网格中的所有值而不是wpf中的(数据网格)子项

c# - 快速随机数生成 - 每毫秒多次

c# - 在 C# 中将简单数字字符串转换为 Int 时引发格式异常

redis - 如何让redis-server进程在前台运行?

node.js - Redis time() 有时会返回 future 的时间

c# - 类错误 - 该方法需要对象引用

asp.net - 在 SQL Server 中使用 Redis

Redis ZRANGEBYSCORE : what is offset and count

redis - 从现有 Redis 集群中删除主节点