I have a program, which will poll on a certain key from the redis datastore, and do something when the value satisfies a certain condition.
However, I think periodically polling on redis is quite inefficient, I’m wondering if there is a “trigger” mechanism for redis, when the value changes and satisfies the condition, the trigger will be called. The trigger might be a RPC function, or an HTTP msg, or something else, so that I don’t need to poll on it any more, just like the difference between poll and interrupt.
Is this possible?
You can use the Pub/Sub feature of Redis. It’s exactly what you need given your circumstances as you described.
Essentially, you
SUBSCRIBEto a “channel”, and the other part of your application writes (PUBLISH) the value being changed to that channel. Your subscriber (consumer, the client that wants to know about the change) will get notified in virtually realtime.