Last active
August 29, 2015 14:06
-
-
Save sheldonh/6217cf553d71ce827598 to your computer and use it in GitHub Desktop.
Tiny sentinel for a redis cluster in a docker cloud
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 redis = require('haredis'); | |
var uuid = require('node-uuid'); | |
var swig = require('swig'); | |
var defaultRedises = '{{REDIS1_PORT_10000_TCP_ADDR}}:10000 {{REDIS2_PORT_10000_TCP_ADDR}}:10000 {{REDIS3_PORT_10000_TCP_ADDR}}:10000'; | |
var template = process.env.REDISES || defaultRedises; | |
var redises = swig.compile(template)(process.env).split(/\s+/); | |
var id = process.env.HOSTNAME || uuid.v4(); | |
var keepaliveMilliseconds = process.env.KEEPALIVE_MS || 3000; | |
console.log("redis-node-sentinel " + id + " monitoring " + redises); | |
var client = redis.createClient(redises); | |
var keepAlive = function() { | |
var lww = "redis-node-sentinel " + id + " keepalive at " + Date.now(); | |
// Writing is probably paranoid; testing required | |
client.set("haredis:keepalive", lww, function(err, reply) { | |
if (err !== null) { | |
console.log(lww + " error, aborting"); | |
throw err; | |
} else { | |
console.log(lww + " write " + reply); | |
setTimeout(keepAlive, keepaliveMilliseconds); | |
} | |
}); | |
}; | |
keepAlive(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment