You've already forked node-redis
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:
@@ -425,6 +425,19 @@ describe('Client', () => {
|
|||||||
);
|
);
|
||||||
}, GLOBAL.SERVERS.OPEN);
|
}, 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 => {
|
testUtils.testWithClient('with script', async client => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await client.multi()
|
await client.multi()
|
||||||
|
@@ -611,6 +611,10 @@ export default class RedisClient<
|
|||||||
selectedDB?: number,
|
selectedDB?: number,
|
||||||
chainId?: symbol
|
chainId?: symbol
|
||||||
): Promise<Array<RedisCommandRawReply>> {
|
): Promise<Array<RedisCommandRawReply>> {
|
||||||
|
if (!this.#socket.isOpen) {
|
||||||
|
return Promise.reject(new ClientClosedError());
|
||||||
|
}
|
||||||
|
|
||||||
const promise = Promise.all(
|
const promise = Promise.all(
|
||||||
commands.map(({ args }) => {
|
commands.map(({ args }) => {
|
||||||
return this.#queue.addCommand(args, { chainId });
|
return this.#queue.addCommand(args, { chainId });
|
||||||
|
Reference in New Issue
Block a user