aboutsummaryrefslogtreecommitdiffstats
path: root/signaling-server/node_modules/socket.io/node_modules/redis/examples/extend.js
blob: 488b8c2dc5da870ca2ec5a5adf430f9be0a65cf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var redis = require("redis"),
    client = redis.createClient();

// Extend the RedisClient prototype to add a custom method
// This one converts the results from "INFO" into a JavaScript Object

redis.RedisClient.prototype.parse_info = function (callback) {
    this.info(function (err, res) {
        var lines = res.toString().split("\r\n").sort();
        var obj = {};
        lines.forEach(function (line) {
            var parts = line.split(':');
            if (parts[1]) {
                obj[parts[0]] = parts[1];
            }
        });
        callback(obj)
    });
};

client.parse_info(function (info) {
    console.dir(info);
    client.quit();
});