Skip to content

Commit

Permalink
feat: quit immediately when in reconnecting state (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruimarinho authored and luin committed Jan 4, 2017
1 parent f526ae1 commit a6f04f2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
32 changes: 32 additions & 0 deletions test/functional/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit a6f04f2

Please sign in to comment.