npm install
- In one terminal,
node redisDataProducer.js
- In another terminal,
node redisDataConsumer.js
Voila! You should see three list items being pushed every two seconds and showing up in the terminal of the data consumer.
/node_modules |
{ | |
"name": "node-redis-blocking-push-pop", | |
"version": "1.0.0", | |
"description": "basic node redis blocking push/pop", | |
"author": "scottgwald", | |
"license": "MIT", | |
"dependencies": | |
{ "redis" : "latest" }, | |
"repository": { | |
"type": "git", | |
"url": "https://gist.github.com/5d0e6afe5215d126ce23.git" | |
} | |
} |
r = require('redis'); | |
client = r.createClient(); | |
function waitForPush() { client.brpop(["foolist", 0], function(err, reply) {console.log(reply); waitForPush()})}; | |
waitForPush(); | |
r = require('redis'); | |
client = r.createClient(); | |
cnt = 0; | |
pushStuff = function() {client.lpush(["foolist", "bar " + cnt, "bar " + (cnt + 1), "bar " + (cnt + 2)], function(err, reply) {console.log(reply)}); cnt+=3}; | |
setInterval(pushStuff, 2000); |