简体   繁体   中英

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

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM