Skip to content

Instantly share code, notes, and snippets.

@rturk
Created April 12, 2017 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rturk/f59e76ca104243d2d9f1b6a965f1ad2a to your computer and use it in GitHub Desktop.
Save rturk/f59e76ca104243d2d9f1b6a965f1ad2a to your computer and use it in GitHub Desktop.
Test - Redis FIFO writer to Postgres
import redis from "redis";
client = redis.createClient();
exitProcessor = false;
queueNext = () => {
process.nextTick(() => {
// Messages are pushed with RPUSH, making this a FIFO queue
client.blpop('queue', 1, queueFn);
})
};
queueFn = function(err, msg) {
if (!err && msg && msg.length === 2) { // Message is always array with two values
console.log(msg);
}
setTimeout(queueNext,10); // pause for 200ms
};
//Start Processor
queueNext();
// Add messages
for(var i=1; i<100; i++) {
client.rpush("queue", "Message " + i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment