Created
April 12, 2017 21:03
-
-
Save rturk/f59e76ca104243d2d9f1b6a965f1ad2a to your computer and use it in GitHub Desktop.
Test - Redis FIFO writer to Postgres
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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