HEXPIREAT(3valkey)

πŸ“¦ version 9.0.6, in fedora 44

πŸ’… 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 the HASH, or key does not exist.
  • 0: The specified NX | XX | GT | LT condition has not been met.
  • 1: The expiration time was applied.
  • 2: When called with 0 seconds.

πŸ‘‘ 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