Skip to content

Commit 24e7486

Browse files
author
Ruben Bridgewater
committed
Fix forgotten optional info section
Fixes #1003
1 parent 093f437 commit 24e7486

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/individualCommands.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ RedisClient.prototype.select = RedisClient.prototype.SELECT = function select (d
3333
};
3434

3535
// Store info in this.server_info after each call
36-
RedisClient.prototype.info = RedisClient.prototype.INFO = function info (callback) {
36+
RedisClient.prototype.info = RedisClient.prototype.INFO = function info (section, callback) {
3737
var self = this;
3838
var ready = this.ready;
39+
if (typeof section === 'function') {
40+
callback = section;
41+
section = 'default';
42+
} else if (section === undefined) {
43+
section = 'default';
44+
}
3945
this.ready = ready || this.offline_queue.length === 0; // keep the execution order intakt
40-
var tmp = this.send_command('info', [], function (err, res) {
46+
var tmp = this.send_command('info', [section], function (err, res) {
4147
if (res) {
4248
var obj = {};
4349
var lines = res.toString().split('\r\n');

test/commands/info.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ describe("The 'info' method", function () {
3737
}, 150);
3838
});
3939

40+
it("works with optional section provided with and without callback", function (done) {
41+
client.set('foo', 'bar');
42+
client.info('keyspace');
43+
client.select(2, function () {
44+
assert.strictEqual(Object.keys(client.server_info).length, 3, 'Key length should be three');
45+
assert(typeof client.server_info.db2 === 'object', 'db2 keyspace should be an object');
46+
});
47+
client.set('foo', 'bar');
48+
client.info('all', function (err, res) {
49+
assert(Object.keys(client.server_info).length > 3, 'Key length should be way above three');
50+
assert.strictEqual(typeof client.server_info.redis_version, 'string');
51+
assert.strictEqual(typeof client.server_info.db2, 'object');
52+
done();
53+
});
54+
});
55+
4056
it("emit error after a failure", function (done) {
4157
client.info();
4258
client.once('error', function (err) {

0 commit comments

Comments
 (0)