Skip to content

Commit 146d881

Browse files
author
Ruben Bridgewater
committed
Fix send_command always returning should_buffer boolean
Fix .auth, .select and .exec to return the should_buffer boolean
1 parent e47ba4a commit 146d881

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Features
1414

1515
Bugfixes
1616

17-
- Fix a javascript parser regression introduced in 2.0 that could result in timeouts on high load. (@BridgeAR)
17+
- Fix a javascript parser regression introduced in 2.0 that could result in timeouts on high load. (@BridgeAR)
18+
- Fixed should_buffer boolean for .exec, .select and .auth commands not being returned (@BridgeAR)
1819

1920
## v2.1.0 - Oct 02, 2015
2021

index.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,11 @@ RedisClient.prototype.send_command = function (command, args, callback) {
677677
err = new Error('send_command: ' + command + ' value must not be undefined or null');
678678
err.command = command;
679679
if (callback) {
680-
return callback && callback(err);
680+
callback(err);
681+
} else {
682+
this.emit('error', err);
681683
}
682-
this.emit('error', err);
683-
return;
684+
return false;
684685
}
685686
}
686687

@@ -715,7 +716,8 @@ RedisClient.prototype.send_command = function (command, args, callback) {
715716
this.offline_queue.push(command_obj);
716717
this.should_buffer = true;
717718
}
718-
return;
719+
// Return false to signal no buffering
720+
return false;
719721
}
720722

721723
if (command === 'subscribe' || command === 'psubscribe' || command === 'unsubscribe' || command === 'punsubscribe') {
@@ -728,7 +730,7 @@ RedisClient.prototype.send_command = function (command, args, callback) {
728730
err = new Error('Connection in subscriber mode, only subscriber commands may be used');
729731
err.command = command.toUpperCase();
730732
this.emit('error', err);
731-
return;
733+
return false;
732734
}
733735
this.command_queue.push(command_obj);
734736
this.commands_sent += 1;
@@ -916,8 +918,7 @@ commands.forEach(function (fullCommand) {
916918
// store db in this.select_db to restore it on reconnect
917919
RedisClient.prototype.select = RedisClient.prototype.SELECT = function (db, callback) {
918920
var self = this;
919-
920-
this.send_command('select', [db], function (err, res) {
921+
return this.send_command('select', [db], function (err, res) {
921922
if (err === null) {
922923
self.selected_db = db;
923924
}
@@ -939,16 +940,16 @@ RedisClient.prototype.auth = RedisClient.prototype.AUTH = function (pass, callba
939940
} else {
940941
this.emit('error', err);
941942
}
942-
return;
943+
return false;
943944
}
944945
this.auth_pass = pass;
945946
debug('Saving auth as ' + this.auth_pass);
946947
// Only run the callback once. So do not safe it if already connected
947948
if (this.connected) {
948-
this.send_command('auth', [this.auth_pass], callback);
949-
} else {
950-
this.auth_callback = callback;
949+
return this.send_command('auth', [this.auth_pass], callback);
951950
}
951+
this.auth_callback = callback;
952+
return false;
952953
};
953954

954955
RedisClient.prototype.hmset = RedisClient.prototype.HMSET = function (key, args, callback) {
@@ -1048,7 +1049,7 @@ Multi.prototype.exec = Multi.prototype.EXEC = function (callback) {
10481049
this.send_command(command, args, index, cb);
10491050
}
10501051

1051-
this._client.send_command('exec', [], function(err, replies) {
1052+
return this._client.send_command('exec', [], function(err, replies) {
10521053
self.execute_callback(err, replies);
10531054
});
10541055
};

test/commands/multi.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,12 @@ describe("The 'multi' method", function () {
203203
});
204204

205205
it('runs a multi without any further commands', function(done) {
206-
client.multi().exec(function(err, res) {
206+
var buffering = client.multi().exec(function(err, res) {
207207
assert.strictEqual(err, null);
208208
assert.strictEqual(res.length, 0);
209209
done();
210210
});
211+
assert(typeof buffering === 'boolean');
211212
});
212213

213214
it('allows multiple operations to be performed using a chaining API', function (done) {

test/commands/select.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ describe("The 'select' method", function () {
2424
});
2525

2626
it("returns an error if redis is not connected", function (done) {
27-
client.select(1, function (err, res) {
27+
var buffering = client.select(1, function (err, res) {
2828
assert(err.message.match(/The connection has already been closed/));
2929
done();
3030
});
31+
assert(typeof buffering === 'boolean');
3132
});
3233
});
3334

@@ -36,7 +37,7 @@ describe("The 'select' method", function () {
3637

3738
beforeEach(function (done) {
3839
client = redis.createClient.apply(redis.createClient, args);
39-
client.once("connect", function () { done(); });
40+
client.once("ready", function () { done(); });
4041
});
4142

4243
afterEach(function () {
@@ -46,11 +47,12 @@ describe("The 'select' method", function () {
4647
it("changes the database and calls the callback", function (done) {
4748
// default value of null means database 0 will be used.
4849
assert.strictEqual(client.selected_db, null, "default db should be null");
49-
client.SELECT(1, function (err, res) {
50+
var buffering = client.SELECT(1, function (err, res) {
5051
helper.isNotError()(err, res);
5152
assert.strictEqual(client.selected_db, 1, "db should be 1 after select");
5253
done();
5354
});
55+
assert(typeof buffering === 'boolean');
5456
});
5557

5658
describe("and a callback is specified", function () {

test/commands/setex.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ describe("The 'setex' method", function () {
2929
});
3030

3131
it('returns an error if no value is provided', function (done) {
32-
client.SETEX(["setex key", "100", undefined], helper.isError(done));
32+
var buffering = client.SETEX(["setex key", "100", undefined], helper.isError(done));
33+
assert(typeof buffering === 'boolean');
3334
});
3435

3536
afterEach(function () {

0 commit comments

Comments
 (0)