我们有一些具有给定 TTL 的 Redis 键,我们希望订阅这些键,并在 TTL 过期后采取行动(类似于作业调度程序)。
这在单主机环境中效果很好,当您在 ServiceStack 中使用其 Redis 客户端订阅 '__keyspace@0__:expired'
时,该服务将选择它并采取操作。太棒了...
...直到您设置了高可用性拓扑,并且该集群中有多个 API 实例。然后,每个主机似乎都在接收该消息并可能利用它执行操作。
我知道键空间通知的工作方式与传统的发布/订阅或消息传递层事件并不完全相同,但是有没有办法对这些类型的事件执行某种确认,以便在结束时一天,只有一个宿主会执行任务?
否则,有没有办法延迟消息发布?
谢谢!
最佳答案
如 https://redis.io/topics/notifications 中所述
very node of a Redis cluster generates events about its own subset of the keyspace as described above. However, unlike regular Pub/Sub communication in a cluster, events' notifications are not broadcasted to all nodes. Put differently, keyspace events are node-specific. This means that to receive all keyspace events of a cluster, clients need to subscribe to each of the nodes.
因此客户端应该创建到每个节点的单独连接以获取 Redis 键空间通知。
关于使用 ServiceStack 在分布式环境中订阅 Redis 键空间通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41540750/