-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathHEXPIRE.ts
42 lines (37 loc) · 1.14 KB
/
HEXPIRE.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Command, NullReply, RedisArgument } from "../RESP/types";
import { RedisVariadicArgument, pushVariadicArgument } from "./generic-transformers";
/**
* @readonly
* @enum {number}
*/
export const HASH_EXPIRATION = {
/** @property {number} */
/** The field does not exist */
FieldNotExists: -2,
/** @property {number} */
/** Specified NX | XX | GT | LT condition not met */
ConditionNotMet: 0,
/** @property {number} */
/** Expiration time was set or updated */
Updated: 1,
/** @property {number} */
/** Field deleted because the specified expiration time is in the past */
Deleted: 2
} as const;
export type HashExpiration = typeof HASH_EXPIRATION[keyof typeof HASH_EXPIRATION];
export default {
FIRST_KEY_INDEX: 1,
transformArguments(
key: RedisArgument,
fields: RedisVariadicArgument,
seconds: number,
mode?: 'NX' | 'XX' | 'GT' | 'LT',
) {
const args = ['HEXPIRE', key, seconds.toString()];
if (mode) {
args.push(mode);
}
return pushVariadicArgument(args, fields);
},
transformReply: undefined as unknown as () => NullReply | Array<HashExpiration>
} as const satisfies Command;