From 24e7486a5adc47b59410007d5f190e3097e01c3b Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 15 Mar 2016 09:59:09 +0100 Subject: [PATCH] Fix forgotten optional info section Fixes #1003 --- lib/individualCommands.js | 10 ++++++++-- test/commands/info.spec.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/individualCommands.js b/lib/individualCommands.js index b162238cbe..e4c871842a 100644 --- a/lib/individualCommands.js +++ b/lib/individualCommands.js @@ -33,11 +33,17 @@ RedisClient.prototype.select = RedisClient.prototype.SELECT = function select (d }; // Store info in this.server_info after each call -RedisClient.prototype.info = RedisClient.prototype.INFO = function info (callback) { +RedisClient.prototype.info = RedisClient.prototype.INFO = function info (section, callback) { var self = this; var ready = this.ready; + if (typeof section === 'function') { + callback = section; + section = 'default'; + } else if (section === undefined) { + section = 'default'; + } this.ready = ready || this.offline_queue.length === 0; // keep the execution order intakt - var tmp = this.send_command('info', [], function (err, res) { + var tmp = this.send_command('info', [section], function (err, res) { if (res) { var obj = {}; var lines = res.toString().split('\r\n'); diff --git a/test/commands/info.spec.js b/test/commands/info.spec.js index 64daf7acdf..bb628a757b 100644 --- a/test/commands/info.spec.js +++ b/test/commands/info.spec.js @@ -37,6 +37,22 @@ describe("The 'info' method", function () { }, 150); }); + it("works with optional section provided with and without callback", function (done) { + client.set('foo', 'bar'); + client.info('keyspace'); + client.select(2, function () { + assert.strictEqual(Object.keys(client.server_info).length, 3, 'Key length should be three'); + assert(typeof client.server_info.db2 === 'object', 'db2 keyspace should be an object'); + }); + client.set('foo', 'bar'); + client.info('all', function (err, res) { + assert(Object.keys(client.server_info).length > 3, 'Key length should be way above three'); + assert.strictEqual(typeof client.server_info.redis_version, 'string'); + assert.strictEqual(typeof client.server_info.db2, 'object'); + done(); + }); + }); + it("emit error after a failure", function (done) { client.info(); client.once('error', function (err) {