Skip to content

Instantly share code, notes, and snippets.

@blindsey
Created June 15, 2012 19:13
Show Gist options
  • Save blindsey/2938252 to your computer and use it in GitHub Desktop.
Save blindsey/2938252 to your computer and use it in GitHub Desktop.
node.js redis status page
app.get('/redis-status', function(req, res, next) {
redis.info(function(error, result) {
if (error) { return next(error); }
var info = {};
result.split(/\r\n/).forEach(function(line) {
var fields = line.split(/:/);
info[fields[0]] = fields[1];
});
var data = { saved: true };
if (info.changes_since_last_save !== '0') {
var last = parseInt(info.last_save_time, 10);
var lag = new Date().getTime() / 1000 - last;
data.saved = lag <= 900;
}
if (info.role === 'slave') {
var master = parseInt(info.master_last_io_seconds_ago, 10);
data.slave = master <= 10;
}
res.send(data);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment