Tuesday 14 March 2017

Node.js and Redis production setup

I have the consumer.js and producer.js as follow. How can I signal the consumer when new element entered the queues? Also, on the production environment, how do I setup consumer.js always to be run in the background?

//File producer.js 
var redis = require('redis');
var client = redis.createClient('6379', 'localhost');


client.rpush('k', 'abc', function(err) { });
client.rpush('k', 'xyz', function(err) { });
client.rpush('k', 'abc', function(err) { });
client.rpush('k', 'xyz', function(err) { });
client.rpush('k', 'abc', function(err) { });
client.rpush('k', 'xyz', function(err) { });
client.rpush('k', 'abc', function(err) { });
client.rpush('k', 'xyz', function(err) { });



//File consumer.js

var redis = require('redis');
var client = redis.createClient('6379', 'localhost');

client.blpop('k', 1, function(err, msg) {
    console.log("poped " + msg);
})

client.blpop('k', 1, function(err, msg) {
    console.log("poped " + msg);
})

client.blpop('k', 1, function(err, msg) {
    console.log("poped " + msg);
})



via user1187968

No comments:

Post a Comment