Skip to content

Commit f92f4d0

Browse files
committed
Merge pull request #850 from fintura/fix-late-commands
Fix commands not being rejected after calling .quit Fixes #791
2 parents bfcc0ae + a0c9062 commit f92f4d0

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
@@ -649,7 +649,7 @@ function Command(command, args, sub_command, buffer_args, callback) {
649649
}
650650

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

654654
// if (typeof callback === "function") {}
655655
// probably the fastest way:
@@ -686,7 +686,9 @@ RedisClient.prototype.send_command = function (command, args, callback) {
686686
return;
687687
}
688688
if (args[args.length - 1] === undefined || args[args.length - 1] === null) {
689-
var err = new Error('send_command: ' + command + ' value must not be undefined or null');
689+
command = command.toUpperCase();
690+
err = new Error('send_command: ' + command + ' value must not be undefined or null');
691+
err.command_used = command;
690692
if (callback) {
691693
return callback && callback(err);
692694
}
@@ -706,24 +708,25 @@ RedisClient.prototype.send_command = function (command, args, callback) {
706708
command_obj = new Command(command, args, false, buffer_args, callback);
707709

708710
if (!this.ready && !this.send_anyway || !stream.writable) {
709-
if (this.enable_offline_queue) {
710-
if (!stream.writable) {
711-
debug("send command: stream is not writeable.");
711+
if (this.closing || !this.enable_offline_queue) {
712+
command = command.toUpperCase();
713+
if (!this.closing) {
714+
err = new Error(command + ' can\'t be processed. Stream not writeable and enable_offline_queue is deactivated.');
715+
} else {
716+
err = new Error(command + ' can\'t be processed. The connection has already been closed.');
717+
}
718+
err.command_used = command;
719+
if (callback) {
720+
callback(err);
721+
} else {
722+
this.emit('error', err);
712723
}
724+
} else {
713725
debug("Queueing " + command + " for next server connection.");
714726
this.offline_queue.push(command_obj);
715727
this.should_buffer = true;
716-
} else {
717-
var not_writeable_error = new Error('send_command: stream not writeable. enable_offline_queue is false');
718-
if (command_obj.callback) {
719-
command_obj.callback(not_writeable_error);
720-
} else {
721-
this.emit("error", not_writeable_error);
722-
return;
723-
}
724728
}
725-
726-
return false;
729+
return;
727730
}
728731

729732
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)