我可以将 Redis 设置为在键值更改时发布到发布/订阅通道吗?
我可以将 Redis 设置为在键值更改时发布到发布/订阅通道吗?
无论如何,是否可以自动监视这些更改,或者我只需要在集合的一部分中构建它来广播新值?
谢谢!
Can I set up Redis to publish to a pub/sub channel when a key-value is changed?
Is there anyway to monitor these changes automatically or do I just need to build it in a part of the set to broadcast the new value?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这类事情太复杂/不够通用,无法内置到 Redis 中,但无论如何,作为客户端的一部分更容易完成 - 只需在 SET 之后发送 PUBLISH 命令即可。
请注意,与 SUBSCRIBE 不同,PUBLISH 不需要专用连接,因此可以轻松与其他命令集成。
That sort of thing is too complex/not generic enough to be built in to redis, but it is easier to do as part of your client anyway - just send a PUBLISH command after the SET.
Note that unlike SUBSCRIBE, PUBLISH does not require a dedicated connection so is easily integrated with other commands.
从 Redis 2.8.0 开始,支持 KeySpace 通知,它完全可以满足您的需求。您可以在这里阅读更多相关信息 - http://redis.io/topics/notifications
KeySpace 通知是一个占用很少的 CPU 资源,因此默认情况下处于禁用状态。对于更简单的任务,执行@tom-clarkson 上面所说的应该就足够了。
As of Redis 2.8.0, there is support for KeySpace Notifications, which do exactly what you want. You can read more about it here - http://redis.io/topics/notifications
KeySpace notifications are a little cpu intensive, so are disabled by default. For simpler tasks, doing what @tom-clarkson said above should suffice.