HPEXPIRE(3valkey)

πŸ“¦ version 9.0.6, in fedora 44

πŸ’– HPEXPIRE πŸ’–

okay bestie, gather round, because this is hpexpire(3valkey) from the Valkey Command Manual and it's literally the moment your hash fields get a deadline. πŸ•°οΈβœ¨


✨ NAME ✨

hpexpire β€” set expiry time on hash object. periodt. πŸ’…


🌸 SYNOPSIS 🌸

HPEXPIRE key milliseconds [NX | XX | GT | LT] FIELDS numfields field
[field...]

πŸ¦‹ DESCRIPTION πŸ¦‹

So this one is the exact same energy as valkey-hexpire(7) HEXPIRE, no cap β€” the only glow-up is that the time to live of the key is specified in milliseconds instead of seconds. tiny units, big power. ⚑

⚠️ and listen, this part matters: giving a millisecond time of 0 will cause immediate expiration and reclamation of the field(s). like, gone. instantly. poof. πŸ’€

πŸŽ€ OPTIONS πŸŽ€

HPEXPIRE supports a set of options that modify its behavior, and each one is a little vibe check on your fields:

  • NX β€” for each specified field, set the expiration only when the field has no expiration. (first-timers only 🫢)
  • XX β€” for each specified field, set the expiration only when the field has an existing expiration. (already-expiring fields only πŸ‘‘)
  • GT β€” for each specified field, set the expiration only when the new expiration is greater than the current one. (only if you're extending, queen ⬆️)
  • LT β€” for each specified field, set the expiration only when the new expiration is less than the current one. (only if you're shortening, no takebacks ⬇️)

🌈 REPLY 🌈

valkey-protocol(7) Array reply: a list of integer codes showing how the expiry-setting went for each specified field, in the exact same order you requested the fields in. it's giving receipts. 🧾

  • -2: the field does not exist in the HASH, or the key does not exist. 😭
  • 0: the specified NX | XX | GT | LT condition has not been met. πŸ™ˆ
  • 1: the expiration time was applied. slay. ✨
  • 2: when called with 0 seconds. πŸ’€

⭐ COMPLEXITY ⭐

O(N) where N is the number of specified fields. linear, bestie, just how we like it. πŸ“


πŸ’œ 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> HPEXPIRE myhash 10000 FIELDS 2 f2 f3
1) (integer) 1
2) (integer) 1
127.0.0.1:6379> HPTTL myhash FIELDS 3 f1 f2 f3
1) (integer) -1
2) (integer) 9597
3) (integer) 9597

look at that β€” f1 said "no expiry for me, I'm eternal" (-1) while f2 and f3 are on the clock. iconic behaviour. πŸ•πŸ”₯


πŸ”₯ SEE ALSO πŸ”₯

hdel(3valkey), hexists(3valkey), hexpire(3valkey), hexpireat(3valkey), hexpiretime(3valkey), hget(3valkey), hgetall(3valkey), hgetex(3valkey), hincrby(3valkey), hincrbyfloat(3valkey), hkeys(3valkey), hlen(3valkey), hmget(3valkey), hmset(3valkey), hpersist(3valkey), hpexpireat(3valkey), hpexpiretime(3valkey), hpttl(3valkey), hrandfield(3valkey), hscan(3valkey), hset(3valkey), hsetex(3valkey), hsetnx(3valkey), hstrlen(3valkey), httl(3valkey), hvals(3valkey)


okay that's the whole page, bestie!! πŸ’– this one's from version 9.0.0, dated 2025-10-21, and yes it's the HPEXPIRE(3valkey) page in all its glory. go set some expirations, you absolute main character. mwah. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from