Created
September 7, 2014 21:21
-
-
Save Siedrix/ce8d9973b27dea916b0a to your computer and use it in GitHub Desktop.
Redbird example with adding host with redis
This file contains 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 | |
import json | |
register = { | |
"src" : "nodebots-dev.mx", | |
"target" : "http://127.0.0.1:4500/" | |
} | |
registerAsStr = json.dumps(register) | |
r = redis.Redis() | |
r.publish("register", registerAsStr) |
This file contains 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
{ | |
"name": "redbird-test", | |
"version": "0.0.0", | |
"description": "", | |
"main": "proxy.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "BSD-2-Clause", | |
"dependencies": { | |
"redbird": "~0.2.7", | |
"redis": "~0.12.1" | |
} | |
} |
This file contains 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 redbird = new require('redbird'), | |
redis = new require('redis'); | |
var proxy = redbird({ | |
port: 80 | |
}); | |
proxy.register('siedrix-dev.com', 'http://127.0.0.1:4000/'); | |
var r = redis.createClient(); | |
r.subscribe('register'); | |
r.subscribe('unregister'); | |
r.on('message', function(channel, messageStr){ | |
var record; | |
try { | |
record = JSON.parse(messageStr); | |
} catch (e) { | |
console.log('Error =>', e); | |
} | |
if(!record){return;} | |
if(channel === 'register'){ | |
if(record.src && record.target){ | |
proxy.register(record.src, record.target); | |
}else{ | |
console.log('Error => To register you need a src and a target'); | |
} | |
}else if(channel === 'unregister'){ | |
if(record.src){ | |
proxy.unregister(record.src); | |
}else{ | |
console.log('Error => To unregister you need a src'); | |
} | |
}else{ | |
console.log('Error => Channel not recognized'); | |
} | |
}); |
This file contains 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 | |
import json | |
unregister = { | |
"src" : "nodebots-dev.mx" | |
} | |
unregisterAsStr = json.dumps(unregister) | |
r = redis.Redis() | |
r.publish("unregister", unregisterAsStr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment