You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
feat(hash field expiration): Added hash field expiration commands (#2907)
* [CAE-686] Added hash field expiration commands * [CAE-686] Improve HSETEX return type * [CAE-686] Minor pushTuples change, renamed HSETEX test * [CAE-686] Changed hsetex function signature for better consistency with other commands * [CAE-686] Fixed hsetex test * [CAE-686] Bumped docker version to 8.0-M05-pre, enabled and fixed tests
This commit is contained in:
42
packages/client/lib/commands/HGETEX.ts
Normal file
42
packages/client/lib/commands/HGETEX.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { CommandParser } from '../client/parser';
|
||||
import { RedisVariadicArgument } from './generic-transformers';
|
||||
import { ArrayReply, Command, BlobStringReply, NullReply, RedisArgument } from '../RESP/types';
|
||||
|
||||
export interface HGetExOptions {
|
||||
expiration?: {
|
||||
type: 'EX' | 'PX' | 'EXAT' | 'PXAT';
|
||||
value: number;
|
||||
} | {
|
||||
type: 'PERSIST';
|
||||
} | 'PERSIST';
|
||||
}
|
||||
|
||||
export default {
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
fields: RedisVariadicArgument,
|
||||
options?: HGetExOptions
|
||||
) {
|
||||
parser.push('HGETEX');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (options?.expiration) {
|
||||
if (typeof options.expiration === 'string') {
|
||||
parser.push(options.expiration);
|
||||
} else if (options.expiration.type === 'PERSIST') {
|
||||
parser.push('PERSIST');
|
||||
} else {
|
||||
parser.push(
|
||||
options.expiration.type,
|
||||
options.expiration.value.toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
parser.push('FIELDS')
|
||||
|
||||
parser.pushVariadicWithLength(fields);
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply | NullReply>
|
||||
} as const satisfies Command;
|
Reference in New Issue
Block a user