HPEXPIRE(3valkey)
π 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 specifiedNX|XX|GT|LTcondition 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
- 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