0.1.1 • Published 12 years ago
redis-plan v0.1.1
redis-plan
Message queue based on redis for NodeJS and Mangrove internal usage.
Installation
$ npm install redis-planUsage
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.
Parallel Worker
var plan = require('../')();
plan.set('maxCount', 100);
plan('parallel', function(data, next) {
console.log(data);
setTimeout(next, 3000);
});Parallel Queueing
var plan = require('../')();
// just a simple for loop
for (var i=0; i<10; i++) {
plan('parallel', data);
}Async Feedback
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.
Gracefully Quit
process.on('exit', function() {
plan.close();
});License
MIT

