Reputation: 51333
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!
Upvotes: 4
Views: 5419
Reputation: 2665
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.
Upvotes: 6
Reputation: 16174
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.
Upvotes: 10