You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +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:
@@ -1,39 +1,78 @@
|
||||
import { RedisCommandArgument, RedisCommandArguments } from '.';
|
||||
import { RedisArgument, BlobStringReply, NullReply, Command } from '../RESP/types';
|
||||
import { transformEXAT, transformPXAT } from './generic-transformers';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
|
||||
type GetExModes = {
|
||||
EX: number;
|
||||
export type GetExOptions = {
|
||||
type: 'EX' | 'PX';
|
||||
value: number;
|
||||
} | {
|
||||
PX: number;
|
||||
type: 'EXAT' | 'PXAT';
|
||||
value: number | Date;
|
||||
} | {
|
||||
EXAT: number | Date;
|
||||
type: 'PERSIST';
|
||||
} | {
|
||||
PXAT: number | Date;
|
||||
/**
|
||||
* @deprecated Use `{ type: 'EX', value: number }` instead.
|
||||
*/
|
||||
EX: number;
|
||||
} | {
|
||||
PERSIST: true;
|
||||
/**
|
||||
* @deprecated Use `{ type: 'PX', value: number }` instead.
|
||||
*/
|
||||
PX: number;
|
||||
} | {
|
||||
/**
|
||||
* @deprecated Use `{ type: 'EXAT', value: number | Date }` instead.
|
||||
*/
|
||||
EXAT: number | Date;
|
||||
} | {
|
||||
/**
|
||||
* @deprecated Use `{ type: 'PXAT', value: number | Date }` instead.
|
||||
*/
|
||||
PXAT: number | Date;
|
||||
} | {
|
||||
/**
|
||||
* @deprecated Use `{ type: 'PERSIST' }` instead.
|
||||
*/
|
||||
PERSIST: true;
|
||||
};
|
||||
|
||||
export function transformArguments(
|
||||
key: RedisCommandArgument,
|
||||
mode: GetExModes
|
||||
): RedisCommandArguments {
|
||||
export default {
|
||||
FIRST_KEY_INDEX: 1,
|
||||
IS_READ_ONLY: true,
|
||||
transformArguments(key: RedisArgument, options: GetExOptions) {
|
||||
const args = ['GETEX', key];
|
||||
|
||||
if ('EX' in mode) {
|
||||
args.push('EX', mode.EX.toString());
|
||||
} else if ('PX' in mode) {
|
||||
args.push('PX', mode.PX.toString());
|
||||
} else if ('EXAT' in mode) {
|
||||
args.push('EXAT', transformEXAT(mode.EXAT));
|
||||
} else if ('PXAT' in mode) {
|
||||
args.push('PXAT', transformPXAT(mode.PXAT));
|
||||
} else { // PERSIST
|
||||
if ('type' in options) {
|
||||
switch (options.type) {
|
||||
case 'EX':
|
||||
case 'PX':
|
||||
args.push(options.type, options.value.toString());
|
||||
break;
|
||||
|
||||
case 'EXAT':
|
||||
case 'PXAT':
|
||||
args.push(options.type, transformEXAT(options.value));
|
||||
break;
|
||||
|
||||
case 'PERSIST':
|
||||
args.push('PERSIST');
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if ('EX' in options) {
|
||||
args.push('EX', options.EX.toString());
|
||||
} else if ('PX' in options) {
|
||||
args.push('PX', options.PX.toString());
|
||||
} else if ('EXAT' in options) {
|
||||
args.push('EXAT', transformEXAT(options.EXAT));
|
||||
} else if ('PXAT' in options) {
|
||||
args.push('PXAT', transformPXAT(options.PXAT));
|
||||
} else { // PERSIST
|
||||
args.push('PERSIST');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
export declare function transformReply(): RedisCommandArgument | null;
|
||||
},
|
||||
transformReply: undefined as unknown as () => BlobStringReply | NullReply
|
||||
} as const satisfies Command;
|
||||
|
Reference in New Issue
Block a user