Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

HEXPIREAT

Last updated
HEXPIREAT key unix-time-seconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
Group
Hash
Complexity
O(N) where N is the number of fields given
Arity
-6 (at least 6 words, counting the command name)
Flags
write, fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

HEXPIREAT works like HEXPIRE, but instead of a relative time to live you give the absolute moment the fields expire, as a Unix timestamp in seconds. A timestamp that is already in the past deletes the fields at once (result code 2).

Option Effect
NX Set the expiry only on fields that have none.
XX Set the expiry only on fields that already have one.
GT Set the expiry only if it is later than the field’s current one. A field without one never matches.
LT Set the expiry only if it is earlier than the field’s current one. A field without one always matches.

An array with one integer per field, in the order given, under both RESP2 and RESP3:

Code Meaning
-2 The field or the key does not exist.
0 The condition was not met; nothing changed.
1 The expiry was set.
2 The time is already in the past, so the field was deleted.

The errors are the same as for HEXPIRE: the timestamp must be a non-negative integer, and one too far in the future gives ERR invalid expire time in 'hexpireat' command.

127.0.0.1:6379> HSET promo:3 code "SPRING" banner "on"
(integer) 2
127.0.0.1:6379> HEXPIREAT promo:3 1924992000 FIELDS 1 code
1) (integer) 1
127.0.0.1:6379> HEXPIRETIME promo:3 FIELDS 2 code banner
1) (integer) 1924992000
2) (integer) -1
127.0.0.1:6379> HEXPIREAT promo:3 1 FIELDS 1 banner
1) (integer) 2

Same arguments and per-field result codes as Redis 7.4. Valkey 8 does not have hash field expiration.

HEXPIRE, HPEXPIREAT, HEXPIRETIME, HPERSIST, EXPIREAT