开发者

Can I set up Redis to publish to a pub/sub channel when a key-value is changed?

开发者 https://www.devze.com 2023-04-05 12:23 出处:网络
Can I s开发者_高级运维et up Redis to publish to a pub/sub channel when a key-value is changed?

Can I s开发者_高级运维et 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!


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号