From a6f04f297f8bbf905171831757e1cff143ce2b59 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Wed, 4 Jan 2017 10:31:12 +0000 Subject: [PATCH] feat: quit immediately when in reconnecting state (#410) --- lib/redis.js | 6 ++++++ test/functional/connection.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) 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 () {