0
即使订阅了频道,我的程序也会关闭。有没有一个正确的方法来保持这个开放? (当然没有Console.ReadLine();
)如何在订阅时保持StackExchange.Redis打开
using System;
using StackExchange.Redis;
namespace redis.test
{
class Program
{
static void Main(string[] args)
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
ISubscriber sub = redis.GetSubscriber();
sub.Subscribe("test", (channel, message) => {
Console.WriteLine("Got notification: " + (string)message);
});
}
}
}
我想发送的每一个消息之后等待未来的消息,所以的WriteLine更简单的方法。 –
我不确定redis是否有能力向您推送通知,或者您需要请求。如果前者那么你需要检查文档的方式。如果是后者,那么你需要决定你想要检查的频率,然后编写合适的代码来做到这一点。这可以像'while(true)'用'Thread.Sleep'来简化请求一样简单... – Chris
如果在此之后添加更多的代码,则将其放在一个线程中,并将'while(true )'或'睡觉'在那里。 – MDuh