better redis info parser from node-redis

v1.18.x
Baris Soner Usakli 11 years ago
parent 07085f1ff2
commit bbcc2312db

@ -160,26 +160,15 @@
return callback(err);
}
data = data.split("\r\n");
var lines = data.toString().split("\r\n").sort();
var redisData = {};
for (var i in data) {
if (data[i].indexOf(':') == -1 || !data[i])
continue;
try {
data[i] = data[i].replace(/:/, "\":\"");
var json = "{\"" + data[i] + "\"}";
var jsonObject = JSON.parse(json);
for (var key in jsonObject) {
redisData[key] = jsonObject[key];
}
} catch (err) {
winston.warn('can\'t parse redis status variable, ignoring', i, data[i], err);
lines.forEach(function (line) {
var parts = line.split(':');
if (parts[1]) {
redisData[parts[0]] = parts[1];
}
}
});
redisData.raw = JSON.stringify(redisData, null, 4);
redisData.redis = true;

Loading…
Cancel
Save