Message queue based on redis for NodeJS and Mangrove internal usage.
$ npm install redis-plan
initialization
var plan = require('redis-plan')(port, host, option);
for queueing
plan('your queue name in redis', 'your data to transfer to worker');
worker just like this simplely
plan('your queue name in redis', function(data, next) {
// u could start handle `data` from queue
next();
});
In the end, remeber that calling plan.end()
to close the connection to redis.
var plan = require('../')();
plan.set('maxCount', 100);
plan('parallel', function(data, next) {
console.log(data);
setTimeout(next, 3000);
});
var plan = require('../')();
// just a simple for loop
for (var i=0; i<10; i++) {
plan('parallel', data);
}
plan('async-feedback', function(item, next) {
asyncMethod(item, function(err) {
next();
if (err)
plan('error', err.stack);
else
plan('success', item);
});
});
NB: success
, close
and error
is especial keys, which you could use to report
data to redis and local event success
and error
, and in redis you are able
to access these reports at plan:success
, plan:close
and plan:error
.
process.on('exit', function() {
plan.close();
});
MIT