Skip to content

fix: fix various command import issues #2944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bloom/lib/commands/bloom/INFO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command, UnwrapReply, NullReply, NumberReply, TuplesToMapReply, Resp2Reply, SimpleStringReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
import { transformInfoV2Reply } from '.';
import { transformInfoV2Reply } from './helpers';

export type BfInfoReplyMap = TuplesToMapReply<[
[SimpleStringReply<'Capacity'>, NumberReply],
Expand Down
29 changes: 29 additions & 0 deletions packages/bloom/lib/commands/bloom/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { RESP_TYPES, TypeMapping } from "@redis/client";

export function transformInfoV2Reply<T>(reply: Array<any>, typeMapping?: TypeMapping): T {
const mapType = typeMapping ? typeMapping[RESP_TYPES.MAP] : undefined;

switch (mapType) {
case Array: {
return reply as unknown as T;
}
case Map: {
const ret = new Map<string, any>();

for (let i = 0; i < reply.length; i += 2) {
ret.set(reply[i].toString(), reply[i + 1]);
}

return ret as unknown as T;
}
default: {
const ret = Object.create(null);

for (let i = 0; i < reply.length; i += 2) {
ret[reply[i].toString()] = reply[i + 1];
}

return ret as unknown as T;
}
}
}
33 changes: 3 additions & 30 deletions packages/bloom/lib/commands/bloom/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RedisCommands, TypeMapping } from '@redis/client/dist/lib/RESP/types';
import type { RedisCommands } from '@redis/client/dist/lib/RESP/types';

import ADD from './ADD';
import CARD from './CARD';
Expand All @@ -10,7 +10,8 @@ import MADD from './MADD';
import MEXISTS from './MEXISTS';
import RESERVE from './RESERVE';
import SCANDUMP from './SCANDUMP';
import { RESP_TYPES } from '@redis/client';

export * from './helpers';

export default {
ADD,
Expand All @@ -34,31 +35,3 @@ export default {
SCANDUMP,
scanDump: SCANDUMP
} as const satisfies RedisCommands;

export function transformInfoV2Reply<T>(reply: Array<any>, typeMapping?: TypeMapping): T {
const mapType = typeMapping ? typeMapping[RESP_TYPES.MAP] : undefined;

switch (mapType) {
case Array: {
return reply as unknown as T;
}
case Map: {
const ret = new Map<string, any>();

for (let i = 0; i < reply.length; i += 2) {
ret.set(reply[i].toString(), reply[i + 1]);
}

return ret as unknown as T;
}
default: {
const ret = Object.create(null);

for (let i = 0; i < reply.length; i += 2) {
ret[reply[i].toString()] = reply[i + 1];
}

return ret as unknown as T;
}
}
}
3 changes: 2 additions & 1 deletion packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ export default class RedisClient<
const reply = await this.sendCommand(parser.redisArgs, commandOptions);

if (transformReply) {
return transformReply(reply, parser.preserve, commandOptions?.typeMapping);
const res = transformReply(reply, parser.preserve, commandOptions?.typeMapping);
return res
}

return reply;
Expand Down
2 changes: 1 addition & 1 deletion packages/json/lib/commands/ARRAPPEND.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisJSON, transformRedisJsonArgument } from './helpers';
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';

export default {
Expand Down
2 changes: 1 addition & 1 deletion packages/json/lib/commands/ARRINDEX.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisJSON, transformRedisJsonArgument } from './helpers';

export interface JsonArrIndexOptions {
range?: {
Expand Down
2 changes: 1 addition & 1 deletion packages/json/lib/commands/ARRINSERT.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, NumberReply, ArrayReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisJSON, transformRedisJsonArgument } from './helpers';

export default {
IS_READ_ONLY: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/json/lib/commands/ARRPOP.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, ArrayReply, NullReply, BlobStringReply, Command, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
import { isArrayReply } from '@redis/client/dist/lib/commands/generic-transformers';
import { transformRedisJsonNullReply } from '.';
import { transformRedisJsonNullReply } from './helpers';

export interface RedisArrPopOptions {
path: RedisArgument;
Expand Down
6 changes: 6 additions & 0 deletions packages/json/lib/commands/GET.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@ describe('JSON.GET', () => {
await client.json.get('key'),
null
);

await client.json.set('noderedis:users:1', '$', { name: 'Alice', age: 32, })
const res = await client.json.get('noderedis:users:1');
assert.equal(typeof res, 'object')
assert.deepEqual(res, { name: 'Alice', age: 32, })

}, GLOBAL.SERVERS.OPEN);
});
12 changes: 8 additions & 4 deletions packages/json/lib/commands/GET.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
import { transformRedisJsonNullReply } from '.';
import { transformRedisJsonNullReply } from './helpers';

export interface JsonGetOptions {
path?: RedisVariadicArgument;
}

export default {
IS_READ_ONLY: false,
parseCommand(parser: CommandParser, key: RedisArgument, options?: JsonGetOptions) {
parseCommand(
parser: CommandParser,
key: RedisArgument,
options?: JsonGetOptions
) {
parser.push('JSON.GET');
parser.pushKey(key);
if (options?.path !== undefined) {
parser.pushVariadic(options.path)
parser.pushVariadic(options.path);
}
},
transformReply: transformRedisJsonNullReply
} as const satisfies Command;
} as const satisfies Command;
2 changes: 1 addition & 1 deletion packages/json/lib/commands/MERGE.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { SimpleStringReply, Command, RedisArgument } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisJSON, transformRedisJsonArgument } from './helpers';

export default {
IS_READ_ONLY: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/json/lib/commands/MGET.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, UnwrapReply, ArrayReply, NullReply, BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { transformRedisJsonNullReply } from '.';
import { transformRedisJsonNullReply } from './helpers';

export default {
IS_READ_ONLY: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/json/lib/commands/MSET.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisJSON, transformRedisJsonArgument } from './helpers';

export interface JsonMSetItem {
key: RedisArgument;
Expand Down
2 changes: 1 addition & 1 deletion packages/json/lib/commands/SET.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, SimpleStringReply, NullReply, Command } from '@redis/client/dist/lib/RESP/types';
import { RedisJSON, transformRedisJsonArgument } from '.';
import { RedisJSON, transformRedisJsonArgument } from './helpers';

export interface JsonSetOptions {
condition?: 'NX' | 'XX';
Expand Down
2 changes: 1 addition & 1 deletion packages/json/lib/commands/STRAPPEND.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, Command, NullReply, NumberReply, ArrayReply } from '@redis/client/dist/lib/RESP/types';
import { transformRedisJsonArgument } from '.';
import { transformRedisJsonArgument } from './helpers';

export interface JsonStrAppendOptions {
path?: RedisArgument;
Expand Down
22 changes: 22 additions & 0 deletions packages/json/lib/commands/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { isNullReply } from "@redis/client/dist/lib/commands/generic-transformers";
import { BlobStringReply, NullReply, UnwrapReply } from "@redis/client/dist/lib/RESP/types";

export function transformRedisJsonNullReply(json: NullReply | BlobStringReply): NullReply | RedisJSON {
console.log('transformRedisJsonNullReply', json)
return isNullReply(json) ? json : transformRedisJsonReply(json);
}

export type RedisJSON = null | boolean | number | string | Date | Array<RedisJSON> | {
[key: string]: RedisJSON;
[key: number]: RedisJSON;
};

export function transformRedisJsonArgument(json: RedisJSON): string {
return JSON.stringify(json);
}

export function transformRedisJsonReply(json: BlobStringReply): RedisJSON {
const res = JSON.parse((json as unknown as UnwrapReply<typeof json>).toString());
console.log('transformRedisJsonReply', json, res)
return res;
}
20 changes: 2 additions & 18 deletions packages/json/lib/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { BlobStringReply, NullReply, UnwrapReply } from '@redis/client/dist/lib/RESP/types';
import ARRAPPEND from './ARRAPPEND';
import ARRINDEX from './ARRINDEX';
import ARRINSERT from './ARRINSERT';
Expand All @@ -23,7 +22,8 @@ import STRAPPEND from './STRAPPEND';
import STRLEN from './STRLEN';
import TOGGLE from './TOGGLE';
import TYPE from './TYPE';
import { isNullReply } from '@redis/client/dist/lib/commands/generic-transformers';

export * from './helpers';

export default {
ARRAPPEND,
Expand Down Expand Up @@ -82,19 +82,3 @@ export default {
type: TYPE
};

export type RedisJSON = null | boolean | number | string | Date | Array<RedisJSON> | {
[key: string]: RedisJSON;
[key: number]: RedisJSON;
};

export function transformRedisJsonArgument(json: RedisJSON): string {
return JSON.stringify(json);
}

export function transformRedisJsonReply(json: BlobStringReply): RedisJSON {
return JSON.parse((json as unknown as UnwrapReply<typeof json>).toString());
}

export function transformRedisJsonNullReply(json: NullReply | BlobStringReply): NullReply | RedisJSON {
return isNullReply(json) ? json : transformRedisJsonReply(json);
}
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/ADD.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ADD from './ADD';
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.';
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from './helpers';
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';

describe('TS.ADD', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/ADD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
parseLabelsArgument,
Timestamp,
parseIgnoreArgument
} from '.';
} from './helpers';

export interface TsIgnoreOptions {
maxTimeDiff: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/ALTER.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import ALTER from './ALTER';
import { TIME_SERIES_DUPLICATE_POLICIES } from '.';
import { TIME_SERIES_DUPLICATE_POLICIES } from './helpers';
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';

describe('TS.ALTER', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/time-series/lib/commands/ALTER.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
import { TsCreateOptions } from './CREATE';
import { parseRetentionArgument, parseChunkSizeArgument, parseDuplicatePolicy, parseLabelsArgument, parseIgnoreArgument } from '.';
import { parseRetentionArgument, parseChunkSizeArgument, parseDuplicatePolicy, parseLabelsArgument, parseIgnoreArgument } from './helpers';


export type TsAlterOptions = Pick<TsCreateOptions, 'RETENTION' | 'CHUNK_SIZE' | 'DUPLICATE_POLICY' | 'LABELS' | 'IGNORE'>;

Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/CREATE.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import CREATE from './CREATE';
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from '.';
import { TIME_SERIES_ENCODING, TIME_SERIES_DUPLICATE_POLICIES } from './helpers';
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';

describe('TS.CREATE', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/CREATE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Labels,
parseLabelsArgument,
parseIgnoreArgument
} from '.';
} from './helpers';
import { TsIgnoreOptions } from './ADD';

export interface TsCreateOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/DEL.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { Timestamp, transformTimestampArgument } from '.';
import { Timestamp, transformTimestampArgument } from './helpers';
import { RedisArgument, NumberReply, Command, } from '@redis/client/dist/lib/RESP/types';

export default {
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/INCRBY.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { RedisArgument, NumberReply, Command } from '@redis/client/dist/lib/RESP/types';
import { Timestamp, transformTimestampArgument, parseRetentionArgument, parseChunkSizeArgument, Labels, parseLabelsArgument, parseIgnoreArgument } from '.';
import { Timestamp, transformTimestampArgument, parseRetentionArgument, parseChunkSizeArgument, Labels, parseLabelsArgument, parseIgnoreArgument } from './helpers';
import { TsIgnoreOptions } from './ADD';

export interface TsIncrByOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/INFO.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'node:assert';
import { TIME_SERIES_DUPLICATE_POLICIES } from '.';
import { TIME_SERIES_DUPLICATE_POLICIES } from './helpers';
import testUtils, { GLOBAL } from '../test-utils';
import INFO, { InfoReply } from './INFO';
import { TIME_SERIES_AGGREGATION_TYPE } from './CREATERULE';
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/INFO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { ArrayReply, BlobStringReply, Command, DoubleReply, NumberReply, ReplyUnion, SimpleStringReply, TypeMapping } from "@redis/client/dist/lib/RESP/types";
import { TimeSeriesDuplicatePolicies } from ".";
import { TimeSeriesDuplicatePolicies } from "./helpers";
import { TimeSeriesAggregationType } from "./CREATERULE";
import { transformDoubleReply } from '@redis/client/dist/lib/commands/generic-transformers';

Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/INFO_DEBUG.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'node:assert';
import { TIME_SERIES_DUPLICATE_POLICIES } from '.';
import { TIME_SERIES_DUPLICATE_POLICIES } from './helpers';
import testUtils, { GLOBAL } from '../test-utils';
import { assertInfo } from './INFO.spec';
import INFO_DEBUG from './INFO_DEBUG';
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/MADD.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { Timestamp, transformTimestampArgument } from '.';
import { Timestamp, transformTimestampArgument } from './helpers';
import { ArrayReply, NumberReply, SimpleErrorReply, Command } from '@redis/client/dist/lib/RESP/types';

export interface TsMAddSample {
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/MGET.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { Command, BlobStringReply, ArrayReply, Resp2Reply, MapReply, TuplesReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
import { resp2MapToValue, resp3MapToValue, SampleRawReply, transformSampleReply } from '.';
import { resp2MapToValue, resp3MapToValue, SampleRawReply, transformSampleReply } from './helpers';
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';

export interface TsMGetOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/MGET_SELECTED_LABELS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { Command, BlobStringReply, NullReply } from '@redis/client/dist/lib/RESP/types';
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
import { TsMGetOptions, parseLatestArgument, parseFilterArgument } from './MGET';
import { parseSelectedLabelsArguments } from '.';
import { parseSelectedLabelsArguments } from './helpers';
import { createTransformMGetLabelsReply } from './MGET_WITHLABELS';

export default {
Expand Down
2 changes: 1 addition & 1 deletion packages/time-series/lib/commands/MGET_WITHLABELS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CommandParser } from '@redis/client/dist/lib/client/parser';
import { Command, BlobStringReply, ArrayReply, Resp2Reply, MapReply, TuplesReply, TypeMapping } from '@redis/client/dist/lib/RESP/types';
import { RedisVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
import { TsMGetOptions, parseLatestArgument, parseFilterArgument } from './MGET';
import { RawLabelValue, resp2MapToValue, resp3MapToValue, SampleRawReply, transformRESP2Labels, transformSampleReply } from '.';
import { RawLabelValue, resp2MapToValue, resp3MapToValue, SampleRawReply, transformRESP2Labels, transformSampleReply } from './helpers';

export interface TsMGetWithLabelsOptions extends TsMGetOptions {
SELECTED_LABELS?: RedisVariadicArgument;
Expand Down
Loading
Loading