You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
fix cluster extractFirstKey skip commandOptions() passed to args (#2439)
* cluster extractFirstKey skip commandOptions() passed to args * cluster with commandOptions unit test * improve performance * fix type * fix type --------- Co-authored-by: Leibale Eidelman <me@leibale.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { strict as assert } from 'assert';
|
|||||||
import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils';
|
import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils';
|
||||||
import RedisCluster from '.';
|
import RedisCluster from '.';
|
||||||
import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT';
|
import { ClusterSlotStates } from '../commands/CLUSTER_SETSLOT';
|
||||||
|
import { commandOptions } from '../command-options';
|
||||||
import { SQUARE_SCRIPT } from '../client/index.spec';
|
import { SQUARE_SCRIPT } from '../client/index.spec';
|
||||||
import { RootNodesUnavailableError } from '../errors';
|
import { RootNodesUnavailableError } from '../errors';
|
||||||
import { spy } from 'sinon';
|
import { spy } from 'sinon';
|
||||||
@@ -178,6 +179,21 @@ describe('Cluster', () => {
|
|||||||
await assert.rejects(cluster.mGet(['a', 'b']));
|
await assert.rejects(cluster.mGet(['a', 'b']));
|
||||||
}, GLOBAL.CLUSTERS.OPEN);
|
}, 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', () => {
|
describe('minimizeConnections', () => {
|
||||||
testUtils.testWithCluster('false', async cluster => {
|
testUtils.testWithCluster('false', async cluster => {
|
||||||
for (const master of cluster.masters) {
|
for (const master of cluster.masters) {
|
||||||
|
@@ -152,11 +152,11 @@ export default class RedisCluster<
|
|||||||
command: C,
|
command: C,
|
||||||
args: Array<unknown>
|
args: Array<unknown>
|
||||||
): Promise<RedisCommandReply<C>> {
|
): Promise<RedisCommandReply<C>> {
|
||||||
const { args: redisArgs, options } = transformCommandArguments(command, args);
|
const { jsArgs, args: redisArgs, options } = transformCommandArguments(command, args);
|
||||||
return transformCommandReply(
|
return transformCommandReply(
|
||||||
command,
|
command,
|
||||||
await this.sendCommand(
|
await this.sendCommand(
|
||||||
RedisCluster.extractFirstKey(command, args, redisArgs),
|
RedisCluster.extractFirstKey(command, jsArgs, redisArgs),
|
||||||
command.IS_READ_ONLY,
|
command.IS_READ_ONLY,
|
||||||
redisArgs,
|
redisArgs,
|
||||||
options
|
options
|
||||||
|
@@ -108,6 +108,7 @@ export function transformCommandArguments<T = ClientCommandOptions>(
|
|||||||
command: RedisCommand,
|
command: RedisCommand,
|
||||||
args: Array<unknown>
|
args: Array<unknown>
|
||||||
): {
|
): {
|
||||||
|
jsArgs: Array<unknown>;
|
||||||
args: RedisCommandArguments;
|
args: RedisCommandArguments;
|
||||||
options: CommandOptions<T> | undefined;
|
options: CommandOptions<T> | undefined;
|
||||||
} {
|
} {
|
||||||
@@ -118,6 +119,7 @@ export function transformCommandArguments<T = ClientCommandOptions>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
jsArgs: args,
|
||||||
args: command.transformArguments(...args),
|
args: command.transformArguments(...args),
|
||||||
options
|
options
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user