How to implement "trigger" for redis datastore?

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 SUBSCRIBE to 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.

How To Successfully Implement Your New Strategy, How To Successfully Implement Your New Strategy. Assign accountability. Someone needs to be responsible for every piece of your strategy. Break down your targets. This is a critical step that cannot be overlooked. Consider where your funds are allocated. Get backing from the leadership team. Before implementing any interventions, the basic program’s governance structure and evaluation plan should be developed. Program strategies and interventions can focus on different levels. Workplace health programs are implemented to improve the health of individual employees and of the overall organization.

If you can use Pub/Sub, that's best. If for some reason that doesn't work, you could also use the (performance-impacting) MONITOR command, which will send you every command the server receives. That's probably not a good idea.

Specifically for lists, you have BLPOP, which will block the connection until a new item is available to pop from a list.

5 top ways to implement a strategic plan, 5 top ways to implement a strategic plan. Communicate and align. CEOs need to begin with clearly communicating their objectives, which should be driven by the company's values and vision. Drive accountability. The CEO should be the first to create goals and then share those goals with the rest of the company. Create Implement definition, any article used in some activity, especially an instrument, tool, or utensil: agricultural implements. See more.

Since Redis 2.8 (released 22 Nov 2013), there is now a feature called Keyspace Notifications which lets clients subscribe to special Pub/Sub channels for keyspace events, which you can use as a trigger on a certain key.

The feature is disabled by default because "while not very sensible the feature uses some CPU power." To enable, send a CONFIG SET command to configure the feature. For example, the following command will enable keyspace events for String commands:

> CONFIG SET notify-keyspace-events K$
OK

Next, use the regular pubsub SUBSCRIBE command to subscribe to the specially-named channel. For example, to listen to keyspace events on the mykey key in DB 0:

> SUBSCRIBE __keyspace@0__:mykey
Reading messages... (press Ctrl-C to quit)

Test out the feature by setting the key's value from another client:

> SET mykey myvalue
OK

You should receive a message in the subscribed client:

1) "message"
2) "__keyspace@0__:mykey"
3) "set"

After receiving the event, you can fetch the updated value and see if it satisfies the condition in your application code.

Process Implementation: How to Implement a New Process at Work , As companies grow, the need to establish processes to help you scale becomes inevitable. We've all reached a place in our role when the way� Few people enjoy change, whether at work or in their personal lives. Whether they resist out of fear of how the change will affect them or simply because making lasting change takes a lot of work, many organizational change efforts fail because of resistance. Large-scale change efforts can be effective, though, with a

The 6-Step Guide to Strategy Implementation, The 6-Step Guide to Strategy Implementation. Define your strategy framework. Build your plan. Define KPIs. Establish your strategy rhythm. Implement strategy reporting. Link performance to strategy. Define implement. implement synonyms, implement pronunciation, implement translation, English dictionary definition of implement. n. 1. A tool, utensil, or other

How to Implement Organizational Development, To have a good plan, you need to know how to implement it. We have listed 7 strategies to help you implement OD in the workplace: 1. Identify� implement definition: 1. to start using a plan or system: 2. a tool that works by being moved by hand or by being pulled…. Learn more.

Strategic Implementation, Implementation is the process that turns strategies and plans into actions in order to accomplish strategic objectives and goals. Implementing your strategic plan� 8 synonyms of implement from the Merriam-Webster Thesaurus, plus 28 related words, definitions, and antonyms. Find another word for implement. Implement: to carry out effectively.

Comments
  • Thanks for your answer. I've read the documentation of Pub/Sub feature of Redis, but still don't understand how to trigger when a value changes. Who will do the "Pub" action? Without polling on the value, how to trigger the "Pub" action?
  • The client which is writing the values should publish that the values have changed.
  • @ciphor if I understand your question, the idea is to change your application logic, so instead of (or in addition to) writing your value to a "plain" redis key, you write it to the channel, so that every subscriber (can be one of course) is immediately notified.
  • Good idea, it would be great if firebase supports the trigger and stored procedure like this. especially asynchronous trigger(to deduplicate actions in a short period)