ServiceStack RedisServerEvents 创建数千个键

ServiceStack RedisServerEvents creating thousands of keys

我将 ServiceStack 与 RedisServerEvents 插件一起使用,以通知连接的客户端数据发生变化。我有两个 Linux 个虚拟机 运行 Apache/mod_mono/ServiceStack,一个 Redis 实例,前面有一个 HAProxy 机器。

我注意到的是,尽管目前只有大约 6 个活跃用户每天测试软件(至少是使用 SSE 的部分),但我的 Redis 实例有数千个以 [=16 开头的键=].它们的 TTL 均为 -1。我可以清除 Redis 实例中的所有键,键的数量会随着时间慢慢增加。

我想弄清楚的是:这是预期的行为吗?我需要对 ServiceStack 或我的客户采取一些行动吗?

应该是 removing the users subscription info when the subscription is removed. But when the AppDomain/Web App is shutdown it won't have cleaned up the existing subscriptions. I've just added a commit,它会在 AppDomain 关闭时尝试清除任何剩余的活动订阅,但如果它没有完全关闭,则可能会有剩余的订阅。

在这种情况下,您可以在启动时调用 Reset() 来清除之前的所有订阅,例如

container.Register<IServerEvents>(c => 
    new RedisServerEvents(c.Resolve<IRedisClientsManager>()));

container.Resolve<IServerEvents>().Reset();

注意:这需要 运行 在任何服务器上有任何活动订阅之前,否则它也会删除它们。

此更改适用于现在 available on MyGet 的 v4.5.7。