I want to be able to run a callback when any change is made in my redis collection. The callback would take the key and value as inputs. Is something like this possible?
Thanks?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can also connect to the Redis server like a follower using the sync command. See How Redis Replication Works? for a quick introduction.
The output of sync command has two phases. In the first phase, the server returns the database dump.rdb file. Once the file is sent, it starts sending commands in the Redis protocol, which is also the AOF format.
Here is the high level picture of what you can do :
SYNCcommandIt seems a lot of work, but you should be able to hack this pretty easily. And it would make a good open source library too!
EDIT : Sync v/s Monitor
Monitoris a debugging command. The response format can (and has) change(d) over time.Syncis used for Master -> Slave replication, and so will be better supportedMonitorwill emit all commands, including read-only commands.Syncwill only get you commands that modify data.Monitorwill log individual commands that are executed within a lua script.Syncwill only transfer the entire lua script, so you will have to parse the script yourself. This is indeed a deal breaker forsync.Monitorwill log commands that did not succeed,Syncwill only log commands that modify data. For example, the commanddel non-existing-keywill be logged by monitor but won’t show up when you run sync.