diff --git a/packages/client/lib/cluster/index.spec.ts b/packages/client/lib/cluster/index.spec.ts index 6b9d35f75f..8200375056 100644 --- a/packages/client/lib/cluster/index.spec.ts +++ b/packages/client/lib/cluster/index.spec.ts @@ -2,6 +2,7 @@ import { strict as assert } from 'assert'; import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils'; import RedisCluster from '.'; import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT'; +import { commandOptions } from '../command-options'; import { SQUARE_SCRIPT } from '../client/index.spec'; import { RootNodesUnavailableError } from '../errors'; import { spy } from 'sinon'; @@ -178,6 +179,21 @@ describe('Cluster', () => { await assert.rejects(cluster.mGet(['a', 'b'])); }, GLOBAL.CLUSTERS.OPEN); + testUtils.testWithCluster('should send commands with commandOptions to correct cluster slot (without redirections)', async cluster => { + // 'a' and 'b' hash to different cluster slots (see previous unit test) + // -> maxCommandRedirections 0: rejects on MOVED/ASK reply + await cluster.set(commandOptions({ isolated: true }), 'a', '1'), + await cluster.set(commandOptions({ isolated: true }), 'b', '2'), + + assert.equal(await cluster.get('a'), '1'); + assert.equal(await cluster.get('b'), '2'); + }, { + ...GLOBAL.CLUSTERS.OPEN, + clusterConfiguration: { + maxCommandRedirections: 0 + } + }); + describe('minimizeConnections', () => { testUtils.testWithCluster('false', async cluster => { for (const master of cluster.masters) { diff --git a/packages/client/lib/cluster/index.ts b/packages/client/lib/cluster/index.ts index 818930c8c8..7e486a376b 100644 --- a/packages/client/lib/cluster/index.ts +++ b/packages/client/lib/cluster/index.ts @@ -152,11 +152,11 @@ export default class RedisCluster< command: C, args: Array ): Promise> { - const { args: redisArgs, options } = transformCommandArguments(command, args); + const { jsArgs, args: redisArgs, options } = transformCommandArguments(command, args); return transformCommandReply( command, await this.sendCommand( - RedisCluster.extractFirstKey(command, args, redisArgs), + RedisCluster.extractFirstKey(command, jsArgs, redisArgs), command.IS_READ_ONLY, redisArgs, options diff --git a/packages/client/lib/commander.ts b/packages/client/lib/commander.ts index 1407a80344..c04f41e1eb 100644 --- a/packages/client/lib/commander.ts +++ b/packages/client/lib/commander.ts @@ -108,6 +108,7 @@ export function transformCommandArguments( command: RedisCommand, args: Array ): { + jsArgs: Array; args: RedisCommandArguments; options: CommandOptions | undefined; } { @@ -118,6 +119,7 @@ export function transformCommandArguments( } return { + jsArgs: args, args: command.transformArguments(...args), options };