Skip to content

Instantly share code, notes, and snippets.

@Siedrix
Created September 7, 2014 21:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Siedrix/ce8d9973b27dea916b0a to your computer and use it in GitHub Desktop.
Save Siedrix/ce8d9973b27dea916b0a to your computer and use it in GitHub Desktop.
Redbird example with adding host with redis
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)
{
"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"
}
}
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');
}
});
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