A super simple Redis-backed queue.
npm install simpleq
var redis =cli = redis;var simpleq =q = cli 'my-simpleq';
q.push(el, cb)Returns number of elements in queue.
q.bpop(cb)(blocking) Returns element popped or null
q.pull(el, cb)Pull out a specific el (the highest/oldest el in the queue to be specific if elements are repeated) from the queue. Returns number of elements removed (0 or 1).
q1.pullpipe(q2, el, cb)Pull and push into another queue atomicly. Returns elements in second queue. (Note, that if el does not exist in q1, it will still be put into q2)
q1.spullpipe(q2, el, cb)is a safe version which will not insert el into q2 unless it has been successfully pulled out of q1. This is done atomically using a lua script.
q1.bpoppipe(q2, cb)(blocking): Pop and push to another queue; returns popped element (also atomic).
q.clear(cb)Clear out the queue
q.list(cb)List all elements in the queue
simpleq's can start listeners that run
bpop continuously and make callbacks when they occur. These two functions are
.poppipelisten. The both accept two options:
max_out(default: 0 ~ infinity) Maximum number of callbacks allowed to be out at one time.
The callbacks on a message from a listener pass a done function that must be called when processing is complete. If not in the same closure,
listener.emit('done'); will suffice.
Note: Calling listen will clone the redis connection, allowing
.push to still work because another connection is being blocked. Calling a listen function more than once will result in a thrown error, as this is not prudent.
var listener = q;// orvar listener = q;// thenlistener;// eventuallylistener// after all jobs have finished; // idempotent if you've already ended the listener
npm install -g nodeunit nodeunit test
See LICENSE file.