HEXPIREAT(3valkey)
π HEXPIREAT β set expiry time on hash fields π
okay bestie, so HEXPIREAT lives in the Valkey Command Manual (section 3valkey) and it's literally the "put a deadline on your hash fields" command. no cap.
β¨ SYNOPSIS β¨
HEXPIREAT key unix-time-seconds [NX | XX | GT | LT] FIELDS numfields
field [field...]
likeβ¦ that's the whole vibe. key, then a unix-time-seconds timestamp, then optionally one of NX | XX | GT | LT, then the literal word FIELDS, then numfields, then your actual field [field...] list. π
π¦ DESCRIPTION π¦
so HEXPIREAT does exactly the same thing, with exactly the same semantics, as HEXPIRE from valkey-hexpire(7) β the ONLY glow-up is how you say when. instead of handing it a TTL (time to live) in seconds, you hand it an absolute Unix timestamp (that's seconds since January 1, 1970, iykyk). π°οΈ
β οΈ heads up bestie: a timestamp in the past will delete the key immediately. not a drill. that's not a bug, that's just how time works. π
for all the specific deets on the semantics of the command, go read the docs for valkey-hexpire(7) HEXPIRE. fr fr, this page is not re-explaining all of that.
πΈ OPTIONS πΈ
HEXPIREAT supports a lil set of options that change how it behaves, and they're giving β¨conditional energyβ¨:
NXβ for each specified field, set the expiration only when the field has no expiration.XXβ for each specified field, set the expiration only when the field has an existing expiration.GTβ for each specified field, set the expiration only when the new expiration is greater than the current one.LTβ for each specified field, set the expiration only when the new expiration is less than the current one.
π«Ά REPLY π«Ά
valkey-protocol(7) Array reply: a list of integer codes telling you how it went for each specified field, in the same order as the fields are requested. so like, position 1 = your first field, position 2 = your second, you get it. π§
-2: Field does not exist in theHASH, or key does not exist.0: The specifiedNX | XX | GT | LTcondition has not been met.1: The expiration time was applied.2: When called with0seconds.
π COMPLEXITY π
O(N) where N is the number of specified fields. linear, bestie, we love a predictable cost. π
π ACL CATEGORIES π
@fast @hash @write
β HISTORY β
- Available since:
9.0.0
π₯ EXAMPLES π₯
127.0.0.1:6379> HSET myhash f1 v1 f2 v2 f3 v3
(integer) 3
27.0.0.1:6379> HEXPIREAT myhash 1754846600 FIELDS 2 f2 f3
1) (integer) 1
2) (integer) 1
127.0.0.1:6379> HEXPIRETIME myhash FIELDS 3 f1 f2 f3
1) (integer) -1
2) (integer) 1754846600
3) (integer) 1754846600
look at that. two fields got their expiry applied (both (integer) 1, ate π
), and then HEXPIRETIME shows f1 chilling with -1 (no expiry, main character of "no deadline") while f2 and f3 are locked in at 1754846600. iconic. β¨
π SEE ALSO π
hdel(3valkey), hexists(3valkey), hexpire(3valkey), hexpiretime(3valkey), hget(3valkey), hgetall(3valkey), hgetex(3valkey), hincrby(3valkey), hincrbyfloat(3valkey), hkeys(3valkey), hlen(3valkey), hmget(3valkey), hmset(3valkey), hpersist(3valkey), hpexpire(3valkey), hpexpireat(3valkey), hpexpiretime(3valkey), hpttl(3valkey), hrandfield(3valkey), hscan(3valkey), hset(3valkey), hsetex(3valkey), hsetnx(3valkey), hstrlen(3valkey), httl(3valkey), hvals(3valkey)
and that's the whole page bestie!! this one's from Valkey 9.0.0, dated 2025-10-21 π β go set some deadlines on your hash fields, and remember: timestamps in the past = instant deletion, so maybe don't do that unless you mean it ππ
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms