Skip to content

Commit a0c9062

Browse files
author
Ruben Bridgewater
committed
Fix commands not being rejected after calling .quit as reported in #791
1 parent 403bfb0 commit a0c9062

File tree

11 files changed

+81
-29
lines changed

11 files changed

+81
-29
lines changed

index.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ function Command(command, args, sub_command, buffer_args, callback) {
661661
}
662662

663663
RedisClient.prototype.send_command = function (command, args, callback) {
664-
var arg, command_obj, i, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0;
664+
var arg, command_obj, i, elem_count, buffer_args, stream = this.stream, command_str = "", buffered_writes = 0, err;
665665

666666
// if (typeof callback === "function") {}
667667
// probably the fastest way:
@@ -698,7 +698,9 @@ RedisClient.prototype.send_command = function (command, args, callback) {
698698
return;
699699
}
700700
if (args[args.length - 1] === undefined || args[args.length - 1] === null) {
701-
var err = new Error('send_command: ' + command + ' value must not be undefined or null');
701+
command = command.toUpperCase();
702+
err = new Error('send_command: ' + command + ' value must not be undefined or null');
703+
err.command_used = command;
702704
if (callback) {
703705
return callback && callback(err);
704706
}
@@ -718,24 +720,25 @@ RedisClient.prototype.send_command = function (command, args, callback) {
718720
command_obj = new Command(command, args, false, buffer_args, callback);
719721

720722
if (!this.ready && !this.send_anyway || !stream.writable) {
721-
if (this.enable_offline_queue) {
722-
if (!stream.writable) {
723-
debug("send command: stream is not writeable.");
723+
if (this.closing || !this.enable_offline_queue) {
724+
command = command.toUpperCase();
725+
if (!this.closing) {
726+
err = new Error(command + ' can\'t be processed. Stream not writeable and enable_offline_queue is deactivated.');
727+
} else {
728+
err = new Error(command + ' can\'t be processed. The connection has already been closed.');
729+
}
730+
err.command_used = command;
731+
if (callback) {
732+
callback(err);
733+
} else {
734+
this.emit('error', err);
724735
}
736+
} else {
725737
debug("Queueing " + command + " for next server connection.");
726738
this.offline_queue.push(command_obj);
727739
this.should_buffer = true;
728-
} else {
729-
var not_writeable_error = new Error('send_command: stream not writeable. enable_offline_queue is false');
730-
if (command_obj.callback) {
731-
command_obj.callback(not_writeable_error);
732-
} else {
733-
this.emit("error", not_writeable_error);
734-
return;
735-
}
736740
}
737-
738-
return false;
741+
return;
739742
}
740743

741744
if (command === "subscribe" || command === "psubscribe" || command === "unsubscribe" || command === "punsubscribe") {

test/commands/dbsize.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("The 'dbsize' method", function () {
3434

3535
it("reports an error", function (done) {
3636
client.dbsize([], function (err, res) {
37-
assert(err.message.match(/Redis connection gone/));
37+
assert(err.message.match(/The connection has already been closed/));
3838
done();
3939
});
4040
});

test/commands/flushdb.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("The 'flushdb' method", function () {
3434

3535
it("reports an error", function (done) {
3636
client.flushdb(function (err, res) {
37-
assert(err.message.match(/Redis connection gone/));
37+
assert(err.message.match(/The connection has already been closed/));
3838
done();
3939
});
4040
});

test/commands/get.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("The 'get' method", function () {
3434

3535
it("reports an error", function (done) {
3636
client.get(key, function (err, res) {
37-
assert(err.message.match(/Redis connection gone/));
37+
assert(err.message.match(/The connection has already been closed/));
3838
done();
3939
});
4040
});

test/commands/getset.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("The 'getset' method", function () {
3636
it("reports an error", function (done) {
3737
client.GET(key, redis.print); // Use the utility function to print the error
3838
client.get(key, function (err, res) {
39-
assert(err.message.match(/Redis connection gone/));
39+
assert(err.message.match(/The connection has already been closed/));
4040
done();
4141
});
4242
});

test/commands/incr.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("The 'incr' method", function () {
3535

3636
it("reports an error", function (done) {
3737
client.incr(function (err, res) {
38-
assert(err.message.match(/Redis connection gone/));
38+
assert(err.message.match(/The connection has already been closed/));
3939
done();
4040
});
4141
});

test/commands/mset.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("The 'mset' method", function () {
3636

3737
it("reports an error", function (done) {
3838
client.mset(key, value, key2, value2, function (err, res) {
39-
assert(err.message.match(/Redis connection gone/));
39+
assert(err.message.match(/The connection has already been closed/));
4040
done();
4141
});
4242
});

test/commands/multi.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("The 'multi' method", function () {
3535
it("reports an error", function (done) {
3636
client.multi();
3737
client.exec(function (err, res) {
38-
assert(err.message.match(/Redis connection gone/));
38+
assert(err.message.match(/The connection has already been closed/));
3939
done();
4040
});
4141
});

test/commands/select.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("The 'select' method", function () {
2626

2727
it("returns an error if redis is not connected", function (done) {
2828
client.select(1, function (err, res) {
29-
assert(err.message.match(/Redis connection gone/));
29+
assert(err.message.match(/The connection has already been closed/));
3030
done();
3131
});
3232
});

test/commands/set.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("The 'set' method", function () {
3434

3535
it("reports an error", function (done) {
3636
client.set(key, value, function (err, res) {
37-
assert(err.message.match(/Redis connection gone/));
37+
assert(err.message.match(/The connection has already been closed/));
3838
done();
3939
});
4040
});

0 commit comments

Comments
 (0)