1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

V5 bringing RESP3, Sentinel and TypeMapping to node-redis

RESP3 Support
   - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion.
 
Sentinel

TypeMapping

Correctly types Multi commands

Note: some API changes to be further documented in v4-to-v5.md
This commit is contained in:
Shaya Potter
2024-10-15 17:46:52 +03:00
committed by GitHub
parent 2fc79bdfb3
commit b2d35c5286
1174 changed files with 45931 additions and 36274 deletions

View File

@@ -1,37 +1,61 @@
import {
SelectedLabels,
pushWithLabelsArgument,
Labels,
transformLablesReply,
transformSampleReply,
Filter,
pushFilterArgument
} from '.';
import { MGetOptions, MGetRawReply, MGetReply } from './MGET';
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
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, pushLatestArgument, pushFilterArgument } from './MGET';
import { RawLabelValue, resp2MapToValue, resp3MapToValue, SampleRawReply, transformRESP2Labels, transformSampleReply } from '.';
export const IS_READ_ONLY = true;
interface MGetWithLabelsOptions extends MGetOptions {
SELECTED_LABELS?: SelectedLabels;
export interface TsMGetWithLabelsOptions extends TsMGetOptions {
SELECTED_LABELS?: RedisVariadicArgument;
}
export function transformArguments(
filter: Filter,
options?: MGetWithLabelsOptions
): RedisCommandArguments {
const args = pushWithLabelsArgument(['TS.MGET'], options?.SELECTED_LABELS);
export type MGetLabelsRawReply2<T extends RawLabelValue> = ArrayReply<
TuplesReply<[
key: BlobStringReply,
labels: ArrayReply<
TuplesReply<[
label: BlobStringReply,
value: T
]>
>,
sample: Resp2Reply<SampleRawReply>
]>
>;
export type MGetLabelsRawReply3<T extends RawLabelValue> = MapReply<
BlobStringReply,
TuplesReply<[
labels: MapReply<BlobStringReply, T>,
sample: SampleRawReply
]>
>;
export function createTransformMGetLabelsReply<T extends RawLabelValue>() {
return {
2(reply: MGetLabelsRawReply2<T>, _, typeMapping?: TypeMapping) {
return resp2MapToValue(reply, ([, labels, sample]) => {
return {
labels: transformRESP2Labels(labels),
sample: transformSampleReply[2](sample)
};
}, typeMapping);
},
3(reply: MGetLabelsRawReply3<T>) {
return resp3MapToValue(reply, ([labels, sample]) => {
return {
labels,
sample: transformSampleReply[3](sample)
};
});
}
} satisfies Command['transformReply'];
}
export default {
FIRST_KEY_INDEX: undefined,
IS_READ_ONLY: true,
transformArguments(filter: RedisVariadicArgument, options?: TsMGetOptions) {
const args = pushLatestArgument(['TS.MGET'], options?.LATEST);
args.push('WITHLABELS');
return pushFilterArgument(args, filter);
}
export interface MGetWithLabelsReply extends MGetReply {
labels: Labels;
};
export function transformReply(reply: MGetRawReply): Array<MGetWithLabelsReply> {
return reply.map(([key, labels, sample]) => ({
key,
labels: transformLablesReply(labels),
sample: transformSampleReply(sample)
}));
}
},
transformReply: createTransformMGetLabelsReply<BlobStringReply>(),
} as const satisfies Command;