diff --git a/lib/redis.js b/lib/redis.js index 47be4c8e..513c0f44 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -579,6 +579,12 @@ Redis.prototype.sendCommand = function (command, stream) { return command.promise; } + if (!writable && command.name === 'quit' && this.offlineQueue.length === 0) { + this.disconnect(); + command.resolve(new Buffer('OK')); + return command.promise; + } + if (writable) { debug('write command[%d] -> %s(%s)', this.condition.select, command.name, command.args); (stream || this.stream).write(command.toWritable()); diff --git a/test/functional/connection.js b/test/functional/connection.js index ba3079c7..9301d77d 100644 --- a/test/functional/connection.js +++ b/test/functional/connection.js @@ -146,6 +146,38 @@ describe('connection', function () { } }); }); + + it('should skip reconnecting if quitting before connecting', function (done) { + var count = 0; + var redis = new Redis({ + port: 8999, + retryStrategy: function () { + count++; + } + }); + + redis.quit().then(function (result) { + expect(result).to.eql('OK'); + expect(count).to.eql(0); + done(); + }); + }); + + it('should skip reconnecting if quitting before connecting (buffer)', function (done) { + var count = 0; + var redis = new Redis({ + port: 8999, + retryStrategy: function () { + count++; + } + }); + + redis.quitBuffer().then(function (result) { + expect(result).to.be.instanceof(Buffer); + expect(result.toString()).to.eql('OK'); + done(); + }); + }); }); describe('connectionName', function () {