extend.js 667 B

123456789101112131415161718192021222324
  1. var redis = require("redis"),
  2. client = redis.createClient();
  3. // Extend the RedisClient prototype to add a custom method
  4. // This one converts the results from "INFO" into a JavaScript Object
  5. redis.RedisClient.prototype.parse_info = function (callback) {
  6. this.info(function (err, res) {
  7. var lines = res.toString().split("\r\n").sort();
  8. var obj = {};
  9. lines.forEach(function (line) {
  10. var parts = line.split(':');
  11. if (parts[1]) {
  12. obj[parts[0]] = parts[1];
  13. }
  14. });
  15. callback(obj)
  16. });
  17. };
  18. client.parse_info(function (info) {
  19. console.dir(info);
  20. client.quit();
  21. });