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

Support redis 2.4 info command

Fixes #1008
This commit is contained in:
Ruben Bridgewater
2016-03-16 23:40:25 +01:00
parent eb9500bb9f
commit 359820c766
2 changed files with 20 additions and 8 deletions

View File

@@ -37,14 +37,14 @@ RedisClient.prototype.select = RedisClient.prototype.SELECT = function select (d
RedisClient.prototype.info = RedisClient.prototype.INFO = function info (section, callback) { RedisClient.prototype.info = RedisClient.prototype.INFO = function info (section, callback) {
var self = this; var self = this;
var ready = this.ready; var ready = this.ready;
var args = [];
if (typeof section === 'function') { if (typeof section === 'function') {
callback = section; callback = section;
section = 'default'; } else if (section !== undefined) {
} else if (section === undefined) { args = Array.isArray(section) ? section : [section];
section = 'default';
} }
this.ready = ready || this.offline_queue.length === 0; // keep the execution order intakt this.ready = ready || this.offline_queue.length === 0; // keep the execution order intakt
var tmp = this.send_command('info', [section], function (err, res) { var tmp = this.send_command('info', args, function (err, res) {
if (res) { if (res) {
var obj = {}; var obj = {};
var lines = res.toString().split('\r\n'); var lines = res.toString().split('\r\n');

View File

@@ -12,14 +12,14 @@ describe("The 'info' method", function () {
describe("using " + parser + " and " + ip, function () { describe("using " + parser + " and " + ip, function () {
var client; var client;
before(function (done) { beforeEach(function (done) {
client = redis.createClient.apply(null, args); client = redis.createClient.apply(null, args);
client.once("ready", function () { client.once("ready", function () {
client.flushall(done); client.flushall(done);
}); });
}); });
after(function () { afterEach(function () {
client.end(true); client.end(true);
}); });
@@ -41,9 +41,10 @@ describe("The 'info' method", function () {
client.set('foo', 'bar'); client.set('foo', 'bar');
client.info('keyspace'); client.info('keyspace');
client.select(2, function () { client.select(2, function () {
assert.strictEqual(Object.keys(client.server_info).length, 3, 'Key length should be three'); assert.strictEqual(Object.keys(client.server_info).length, 2, 'Key length should be three');
assert(typeof client.server_info.db2 === 'object', 'db2 keyspace should be an object'); assert.strictEqual(typeof client.server_info.db0, 'object', 'db0 keyspace should be an object');
}); });
client.info(['keyspace']);
client.set('foo', 'bar'); client.set('foo', 'bar');
client.info('all', function (err, res) { client.info('all', function (err, res) {
assert(Object.keys(client.server_info).length > 3, 'Key length should be way above three'); assert(Object.keys(client.server_info).length > 3, 'Key length should be way above three');
@@ -53,6 +54,17 @@ describe("The 'info' method", function () {
}); });
}); });
it('check redis v.2.4 support', function (done) {
var end = helper.callFuncAfter(done, 2);
client.send_command = function (command, args, callback) {
assert.strictEqual(args.length, 0);
assert.strictEqual(command, 'info');
end();
};
client.info();
client.info(function () {});
});
it("emit error after a failure", function (done) { it("emit error after a failure", function (done) {
client.info(); client.info();
client.once('error', function (err) { client.once('error', function (err) {