Last active
December 21, 2015 16:28
-
-
Save shripadk/6333258 to your computer and use it in GitHub Desktop.
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
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