diff --git a/lib/client.spec.ts b/lib/client.spec.ts index f91e5aafbd..57372b1ead 100644 --- a/lib/client.spec.ts +++ b/lib/client.spec.ts @@ -2,9 +2,10 @@ import { strict as assert } from 'assert'; import { once } from 'events'; import { itWithClient, TEST_REDIS_SERVERS, TestRedisServers, waitTillBeenCalled, isRedisVersionGreaterThan } from './test-utils'; import RedisClient from './client'; -import { AbortError } from './errors'; +import { AbortError, WatchError } from './errors'; import { defineScript } from './lua-script'; import { spy } from 'sinon'; +import { commandOptions } from './command-options'; export const SQUARE_SCRIPT = defineScript({ NUMBER_OF_KEYS: 0, @@ -222,7 +223,7 @@ describe('Client', () => { }); }); - describe('multi', () => { + describe.only('multi', () => { itWithClient(TestRedisServers.OPEN, 'simple', async client => { assert.deepEqual( await client.multi() @@ -268,6 +269,25 @@ describe('Client', () => { await client.disconnect(); } }); + + itWithClient(TestRedisServers.OPEN, 'WatchError', async client => { + await client.watch('key'); + + await client.set( + RedisClient.commandOptions({ + isolated: true + }), + 'key', + '1' + ); + + await assert.rejects( + client.multi() + .decr('key') + .exec(), + WatchError + ); + }); }); it('scripts', async () => { diff --git a/lib/multi-command.spec.ts b/lib/multi-command.spec.ts index 65c2a2c3ba..c2a502faee 100644 --- a/lib/multi-command.spec.ts +++ b/lib/multi-command.spec.ts @@ -47,7 +47,7 @@ describe('Multi Command', () => { it('WatchError', async () => { assert.rejects( - RedisMultiCommand.create(() => Promise.resolve(null)).exec(), + RedisMultiCommand.create(() => Promise.resolve([null])).exec(), WatchError ); }); diff --git a/lib/multi-command.ts b/lib/multi-command.ts index 7fa5f86c74..c8a5076596 100644 --- a/lib/multi-command.ts +++ b/lib/multi-command.ts @@ -29,7 +29,7 @@ export interface MultiQueuedCommand { transformReply?: RedisCommand['transformReply']; } -export type RedisMultiExecutor = (queue: Array, chainId?: symbol) => Promise>; +export type RedisMultiExecutor = (queue: Array, chainId?: symbol) => Promise>; export default class RedisMultiCommand { static commandsExecutor(this: RedisMultiCommand, command: RedisCommand, args: Array): RedisMultiCommand { @@ -169,22 +169,22 @@ export default class RedisMultiCommand); - return this.#transformReplies( - rawReplies[rawReplies.length - 1] as Array, - queue - ); + if (execReply === null) { + throw new WatchError(); + } + + return this.#transformReplies(execReply, queue); } async execAsPipeline(): Promise> { @@ -194,19 +194,11 @@ export default class RedisMultiCommand(reply: null | T): T { - if (reply === null) { - throw new WatchError(); - } - - return reply; - } - #transformReplies(rawReplies: Array, queue: Array): Array { return rawReplies.map((reply, i) => { const { transformReply, preservedArguments } = queue[i];