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

Reject multi.exec() promise with ClientClosedError after client disconnect (#2293)

* Add reject multi chain on client disconnect assertion to client test suite

* Reject multi chain exec with client closed error after client disconnect
This commit is contained in:
Matthijs Dabroek
2022-10-26 22:40:14 +02:00
committed by GitHub
parent 0abd950f03
commit c413657357
2 changed files with 17 additions and 0 deletions

View File

@@ -425,6 +425,19 @@ describe('Client', () => {
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('should reject the whole chain upon client disconnect', async client => {
await client.disconnect();
return assert.rejects(
client.multi()
.ping()
.set('key', 'value')
.get('key')
.exec(),
ClientClosedError
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('with script', async client => {
assert.deepEqual(
await client.multi()

View File

@@ -611,6 +611,10 @@ export default class RedisClient<
selectedDB?: number,
chainId?: symbol
): Promise<Array<RedisCommandRawReply>> {
if (!this.#socket.isOpen) {
return Promise.reject(new ClientClosedError());
}
const promise = Promise.all(
commands.map(({ args }) => {
return this.#queue.addCommand(args, { chainId });