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!
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!
Share Improve this question asked Sep 15, 2011 at 3:33 fancyfancy 51.4k64 gold badges156 silver badges230 bronze badges2 Answers
Reset to default 10That sort of thing is too plex/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 mand after the SET.
Note that unlike SUBSCRIBE, PUBLISH does not require a dedicated connection so is easily integrated with other mands.
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.