You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
38 lines
954 B
TypeScript
38 lines
954 B
TypeScript
import { RedisArgument, BlobStringReply, NullReply, Command } from '../RESP/types';
|
|
import { transformEXAT, transformPXAT } from './generic-transformers';
|
|
|
|
export type GetExModes = {
|
|
EX: number;
|
|
} | {
|
|
PX: number;
|
|
} | {
|
|
EXAT: number | Date;
|
|
} | {
|
|
PXAT: number | Date;
|
|
} | {
|
|
PERSIST: true;
|
|
};
|
|
|
|
export default {
|
|
FIRST_KEY_INDEX: 1,
|
|
IS_READ_ONLY: true,
|
|
transformArguments(key: RedisArgument, mode: GetExModes) {
|
|
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
|
|
args.push('PERSIST');
|
|
}
|
|
|
|
return args;
|
|
},
|
|
transformReply: undefined as unknown as () => BlobStringReply | NullReply
|
|
} as const satisfies Command;
|