Skip to content

Commit a6f04f2

Browse files
ruimarinholuin
authored andcommitted
feat: quit immediately when in reconnecting state (#410)
1 parent f526ae1 commit a6f04f2

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/redis.js

+6
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,12 @@ Redis.prototype.sendCommand = function (command, stream) {
579579
return command.promise;
580580
}
581581

582+
if (!writable && command.name === 'quit' && this.offlineQueue.length === 0) {
583+
this.disconnect();
584+
command.resolve(new Buffer('OK'));
585+
return command.promise;
586+
}
587+
582588
if (writable) {
583589
debug('write command[%d] -> %s(%s)', this.condition.select, command.name, command.args);
584590
(stream || this.stream).write(command.toWritable());

test/functional/connection.js

+32
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,38 @@ describe('connection', function () {
146146
}
147147
});
148148
});
149+
150+
it('should skip reconnecting if quitting before connecting', function (done) {
151+
var count = 0;
152+
var redis = new Redis({
153+
port: 8999,
154+
retryStrategy: function () {
155+
count++;
156+
}
157+
});
158+
159+
redis.quit().then(function (result) {
160+
expect(result).to.eql('OK');
161+
expect(count).to.eql(0);
162+
done();
163+
});
164+
});
165+
166+
it('should skip reconnecting if quitting before connecting (buffer)', function (done) {
167+
var count = 0;
168+
var redis = new Redis({
169+
port: 8999,
170+
retryStrategy: function () {
171+
count++;
172+
}
173+
});
174+
175+
redis.quitBuffer().then(function (result) {
176+
expect(result).to.be.instanceof(Buffer);
177+
expect(result.toString()).to.eql('OK');
178+
done();
179+
});
180+
});
149181
});
150182

151183
describe('connectionName', function () {

0 commit comments

Comments
 (0)