RedisClient和RedisPubSubServer之间的ServiceStack.Redis区别

时间:2018-08-07 09:56:04

标签: c# redis servicestack.redis

我已经开始使用ServiceStack.Redis,首先我使用RedisClient,但是在调用Subscription.SubscribeToChannels时出现了一个问题,线程冻结了。 为了解决这个问题,我开始使用RedisPubSubServer,它允许控制订阅并且线程不冻结。 我的问题是-为什么在库中有两个非常相似的类,它们的作用却差不多? RedisClient和RedisPubSubServer有什么区别?我已经阅读了文档,但不清楚为什么两者都存在。

//RedisClient example
var Client = new RedisClient(configuration["ConnectionStrings:Redis"]);
var Subscription = Client.CreateSubscription();
Subscription.OnMessage = (channel, msg) => "Received '{0}' from 
                                                  '{1}'".Print(msg, channel)
//blocking subscription
Subscription.SubscribeToChannels("channel-1");

//RedisPubSubServer example. Non blocking subscription.
var ClientsManager = new PooledRedisClientManager(configuration["ConnectionStrings:Redis"]);
var redisPubSub = new RedisPubSubServer(clientsManager, "channel-1") {
    OnMessage = (channel, msg) => "Received '{0}' from '{1}'".Print(msg, channel)
}.Start();

0 个答案:

没有答案