Skip to content

Instantly share code, notes, and snippets.

@shripadk
Last active December 21, 2015 16:28
Show Gist options
  • Save shripadk/6333258 to your computer and use it in GitHub Desktop.
Save shripadk/6333258 to your computer and use it in GitHub Desktop.
var redis = require('redis');
var client = redis.createClient();
var pullNotifications = function() {
// if notification in list rpop it else block until one is available; timeout=0;
client.brpop('_bitcoin_notifications_', '_bitcoin_notifications_', 0, function(e, data) {
if(!data.length) return;
data = JSON.parse(data[1]);
switch(data.type) {
case "block":
// do something
console.log('new block!');
console.log(data);
break;
case "transaction":
// do something
console.log('new transaction!');
console.log(data);
break;
}
pullNotifications();
});
};
pullNotifications();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment