我有一台使用Redis的远程计算机。我想接收有关Redis事件(更新,新密钥等)的通知。我已经在网上搜索解决方案并登陆了StackExchange.Redis,然后我开始创建Windows服务来监听Redis事件。我找到了代码示例:
var endp = "x.x.x.x:xxxx"
using (ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(endp))
{
IDatabase db = connection.GetDatabase();
ISubscriber subscriber = connection.GetSubscriber();
int f = 0;
subscriber.Subscribe("__keyspace@0__:*", (channel, value) =>
{
if ((string) channel != null)
{
f++;
// Do stuff if some item is added to a hypothethical "users" set in Redis
}
}
);
}
现在我不会得到所有事件,而只是增加计数器。这够了还是我错过了什么?