How can I post objects from Redis when they are added in real time?

I want to start the Node.js process by checking the Redis server for anything you like.

Another process will do pushing sporadically, and the Node process will try to push everything that comes. The Node process will work.

Can someone point me in a good direction?

I'm trying to figure out how to listen to such an event. Of course, I can put it once, but how do I get the Node process to continue listening to any addition to the Redis server?

+4
source share
3 answers

Do you want to use blocking pop: http://redis.io/commands/brpop

function waitForPush () { client.brpop(['list','otherlist',0], function (listName, item) { // do stuff waitForPush(); }); } 
+9
source

This seems like a good option for pub / sub: http://redis.io/topics/pubsub

Your Node.js process, which sporadically pushes Redis, can also post to the channel every time it pushes something. Like this:

 var pushClient = redis.createClient(); //push something onto Redis pushClient.publish("pubsub-channel", "Just pushed something onto Redis"); 

Then your other process will subscribe to this channel. Each time the message event is triggered, you delete everything that was just clicked:

 var client = redis.createClient(); client.subscribe("pubsub-channel"); client.on("message", function(channel, message){ //pop off new item }); 
+11
source

How about a modified version of a recursive function with process.nextTick (...)

 function waitForPush () { client.brpop(['list','otherlist',0], function (listName, item) { // do stuff process.nextTick(waitForPush); }); } 
+1
source

All Articles