1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

Export RedisClient prototype to support extending.

See examples/extend.js for a simple example.
Remove command list from exports while I was in there.
This commit is contained in:
Matt Ranney
2010-10-05 11:29:22 -07:00
parent ddcecc5b29
commit 85bd648adc
3 changed files with 31 additions and 5 deletions

24
examples/extend.js Normal file
View File

@@ -0,0 +1,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();
});