1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

fix #2333 - fix quit reply (#2346)

This commit is contained in:
Leibale Eidelman
2023-01-18 12:55:11 -05:00
committed by GitHub
parent 2042a67f3c
commit fad23973a5
3 changed files with 11 additions and 8 deletions

View File

@@ -841,13 +841,14 @@ describe('Client', () => {
quitPromise = client.quit();
assert.equal(client.isOpen, false);
const [ping] = await Promise.all([
const [ping, quit] = await Promise.all([
pingPromise,
assert.doesNotReject(quitPromise),
quitPromise,
assert.rejects(client.ping(), ClientClosedError)
]);
assert.equal(ping, 'PONG');
assert.equal(quit, 'OK');
}, {
...GLOBAL.SERVERS.OPEN,
disableClientSetup: true

View File

@@ -586,16 +586,17 @@ export default class RedisClient<
pUnsubscribe = this.PUNSUBSCRIBE;
QUIT(): Promise<void> {
return this.#socket.quit(() => {
const quitPromise = this.#queue.addCommand(['QUIT'], {
QUIT(): Promise<string> {
return this.#socket.quit(async () => {
const quitPromise = this.#queue.addCommand<string>(['QUIT'], {
ignorePubSubMode: true
});
this.#tick();
return Promise.all([
const [reply] = await Promise.all([
quitPromise,
this.#destroyIsolationPool()
]);
return reply;
});
}

View File

@@ -240,14 +240,15 @@ export default class RedisSocket extends EventEmitter {
this.emit('end');
}
async quit(fn: () => Promise<unknown>): Promise<void> {
async quit<T>(fn: () => Promise<T>): Promise<T> {
if (!this.#isOpen) {
throw new ClientClosedError();
}
this.#isOpen = false;
await fn();
const reply = await fn();
this.#disconnect();
return reply;
}
#isCorked = false;