Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Last active December 13, 2019 16:11
Show Gist options
  • Save scottgwald/5d0e6afe5215d126ce23 to your computer and use it in GitHub Desktop.
Save scottgwald/5d0e6afe5215d126ce23 to your computer and use it in GitHub Desktop.
basic node-redis blocking push/pop
/node_modules

Basic Node Redis Blocking Push / Pop

  1. npm install
  2. In one terminal, node redisDataProducer.js
  3. 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.

{
"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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment