【发布时间】:2019-05-09 20:53:43
【问题描述】:
Azure Redis 缓存是否允许我设置一个函数,以便在我的缓存中的某个键过期时可靠地触发?
【问题讨论】:
标签: azure-redis-cache redis-cache
Azure Redis 缓存是否允许我设置一个函数,以便在我的缓存中的某个键过期时可靠地触发?
【问题讨论】:
标签: azure-redis-cache redis-cache
您可以使用Redis Pub/Sub 和Redis Keyspace Notifications 组合客户端,让客户端在特定键发生事件或任何键发生特定事件时接收消息。然后,您可以使用pattern-matching subscriptions 接收多个密钥的消息。您还可以从单个客户端订阅多个频道;所有消息都包含要发布到哪个频道,以便您的客户可以决定要做什么。
要在任何以foo 开头的密钥到期时接收消息,请执行以下操作:
notify-keyspace-events 配置值设置为 Kx。为 Azure 设置值的步骤是 here。有关配置值架构的更多详细信息,请参见 here。PSUBSCRIBE '__keyspace@*__:foo*'
SET foo42 bar EX 5
"pmessage","__keyspace@*__:foo*","__keyspace@0__:foo42","expired"
要在任何密钥过期时接收消息,请执行以下操作:
notify-keyspace-events 配置值设置为Ex
PSUBSCRIBE '__keyevent@*__:expired'
SET foo bar EX 5
"pmessage","__keyevent@*__:expired","__keyevent@0__:expired","foo"
为了客户快速开发和调试,我建议使用redis-cli或Redis console in the Azure Portal。
希望这会有所帮助。祝你好运!
【讨论】: