1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00
Files
node-redis/examples/extend.js
Ruben Bridgewater f1a7bcd735 chore: use standard
2017-05-06 07:06:52 +02:00

28 lines
636 B
JavaScript

'use strict'
var redis = require('redis')
var 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.parseInfo = function (callback) {
this.info(function (err, res) {
if (err) throw err
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.parseInfo(function (info) {
console.dir(info)
client.quit()
})