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

fix: loop over arguments instead of spreading (#2160)

* fix: loop over arguments instead of spreading

* update to use concat

* use the returned array from pushVerdictArguments (instead of assuming it'll push to the original array)

* fix "Type 'RedisCommandArguments' is not assignable to type 'string[]'."

* fix "Argument of type 'RedisCommandArgument | RedisCommandArguments[]' is not assignable to parameter of type 'RedisCommandArgument | RedisCommandArgument[]'"

* fix "Type 'RedisCommandArguments' is not assignable to type 'string[]'"

Co-authored-by: Leibale Eidelman <leibale1998@gmail.com>
This commit is contained in:
Brandon Everett
2022-07-13 07:01:35 -04:00
committed by GitHub
parent 71d582368a
commit ac032d82a0
7 changed files with 32 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
import { pushVerdictArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisCommandArgument, RedisCommandArguments } from '@redis/client/dist/lib/commands';
export const FIRST_KEY_INDEX = 1;
@@ -12,9 +13,9 @@ interface InsertOptions {
export function transformArguments(
key: string,
items: string | Array<string>,
items: RedisCommandArgument | Array<RedisCommandArgument>,
options?: InsertOptions
): Array<string> {
): RedisCommandArguments {
const args = ['BF.INSERT', key];
if (options?.CAPACITY) {
@@ -38,9 +39,7 @@ export function transformArguments(
}
args.push('ITEMS');
pushVerdictArguments(args, items);
return args;
return pushVerdictArguments(args, items);
}
export { transformBooleanArrayReply as transformReply } from '@redis/client/dist/lib/commands/generic-transformers';

View File

@@ -1,13 +1,14 @@
import { pushVerdictArguments } from './generic-transformers';
import { RedisCommandArgument, RedisCommandArguments } from '.';
export const IS_READ_ONLY = true;
export function transformArguments(channels?: Array<string> | string): Array<string> {
export function transformArguments(
channels?: Array<RedisCommandArgument> | RedisCommandArgument
): RedisCommandArguments {
const args = ['PUBSUB', 'NUMSUB'];
if (channels) {
pushVerdictArguments(args, channels);
}
if (channels) return pushVerdictArguments(args, channels);
return args;
}

View File

@@ -18,9 +18,10 @@ export function transformArguments(
id: RedisCommandArgument | Array<RedisCommandArgument>,
options?: XClaimOptions
): RedisCommandArguments {
const args = ['XCLAIM', key, group, consumer, minIdleTime.toString()];
pushVerdictArguments(args, id);
const args = pushVerdictArguments(
['XCLAIM', key, group, consumer, minIdleTime.toString()],
id
);
if (options?.IDLE) {
args.push('IDLE', options.IDLE.toString());

View File

@@ -428,7 +428,8 @@ export function pushEvalArguments(args: Array<string>, options?: EvalOptions): A
export function pushVerdictArguments(args: RedisCommandArguments, value: RedisCommandArgument | Array<RedisCommandArgument>): RedisCommandArguments {
if (Array.isArray(value)) {
args.push(...value);
// https://github.com/redis/node-redis/pull/2160
args = args.concat(value);
} else {
args.push(value);
}

View File

@@ -1,4 +1,5 @@
import { pushVerdictArguments } from '@redis/client/dist/lib/commands/generic-transformers';
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
export const FIRST_KEY_INDEX = 1;
@@ -12,11 +13,11 @@ interface GetOptions {
NOESCAPE?: true;
}
export function transformArguments(key: string, options?: GetOptions): Array<string> {
const args = ['JSON.GET', key];
export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments {
let args: RedisCommandArguments = ['JSON.GET', key];
if (options?.path) {
pushVerdictArguments(args, options.path);
args = pushVerdictArguments(args, options.path);
}
if (options?.INDENT) {

View File

@@ -8,6 +8,7 @@ import {
pushFilterArgument
} from '.';
import { MGetRawReply, MGetReply } from './MGET';
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
export const IS_READ_ONLY = true;
@@ -18,14 +19,9 @@ interface MGetWithLabelsOptions {
export function transformArguments(
filter: Filter,
options?: MGetWithLabelsOptions
): Array<string> {
const args = ['TS.MGET'];
pushWithLabelsArgument(args, options?.SELECTED_LABELS);
pushFilterArgument(args, filter);
return args;
): RedisCommandArguments {
const args = pushWithLabelsArgument(['TS.MGET'], options?.SELECTED_LABELS);
return pushFilterArgument(args, filter);
}
export interface MGetWithLabelsReply extends MGetReply {

View File

@@ -313,8 +313,7 @@ export type Filter = string | Array<string>;
export function pushFilterArgument(args: RedisCommandArguments, filter: string | Array<string>): RedisCommandArguments {
args.push('FILTER');
pushVerdictArguments(args, filter);
return args;
return pushVerdictArguments(args, filter);
}
export interface MRangeOptions extends RangeOptions {
@@ -328,10 +327,9 @@ export function pushMRangeArguments(
filter: Filter,
options?: MRangeOptions
): RedisCommandArguments {
pushRangeArguments(args, fromTimestamp, toTimestamp, options);
pushFilterArgument(args, filter);
pushMRangeGroupByArguments(args, options?.GROUPBY);
return args;
args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
args = pushFilterArgument(args, filter);
return pushMRangeGroupByArguments(args, options?.GROUPBY);
}
export type SelectedLabels = string | Array<string>;
@@ -341,7 +339,7 @@ export function pushWithLabelsArgument(args: RedisCommandArguments, selectedLabe
args.push('WITHLABELS');
} else {
args.push('SELECTED_LABELS');
pushVerdictArguments(args, selectedLabels);
args = pushVerdictArguments(args, selectedLabels);
}
return args;
@@ -358,11 +356,10 @@ export function pushMRangeWithLabelsArguments(
filter: Filter,
options?: MRangeWithLabelsOptions
): RedisCommandArguments {
pushRangeArguments(args, fromTimestamp, toTimestamp, options);
pushWithLabelsArgument(args, options?.SELECTED_LABELS);
pushFilterArgument(args, filter);
pushMRangeGroupByArguments(args, options?.GROUPBY);
return args;
args = pushRangeArguments(args, fromTimestamp, toTimestamp, options);
args = pushWithLabelsArgument(args, options?.SELECTED_LABELS);
args = pushFilterArgument(args, filter);
return pushMRangeGroupByArguments(args, options?.GROUPBY);
}
export function transformRangeReply(reply: Array<SampleRawReply>): Array<SampleReply> {