PEXPIREAT(3valkey)
π PEXPIREAT β the valkey manual page, but make it cute π
okay bestie, so this is PEXPIREAT from the Valkey Command Manual (that's the PEXPIREAT(3valkey) page, mwah). Sit down, grab a lil snack, we're learning when a key is gonna ~expire~ β¨
πΈ NAME πΈ
pexpireat β sets the expiration time of a key to a Unix milliseconds timestamp. periodt.
π¦ SYNOPSIS π¦
PEXPIREAT key unix-time-milliseconds [NX | XX | GT | LT]
π DESCRIPTION π
So like, PEXPIREAT does the exact same thing, same energy, same semantics as EXPIREAT over in valkey-expireat(7) β the way that it's literally the same β EXCEPT the Unix time where your key goes poof is given in milliseconds instead of seconds. that's it. that's the whole difference. iconic behavior honestly π
β¨ OPTIONS β¨
PEXPIREAT said "let me have options" and supports this lil set since Redis OSS 7.0:
NXβ set the expiry only when the key has no expiry at all. no expiry? cool, here's one π«ΆXXβ set the expiry only when the key already has an expiry. gotta have one to get one, iykykGTβ set the expiry only when the new expiry is greater than the current oneLTβ set the expiry only when the new expiry is less than the current one
β οΈ heads up bestie: a non-volatile key is treated as an infinite TTL for the purpose ofGTandLT. andGT,LTandNXare mutually exclusive β pick your fighter, you cannot have all three π
π REPLY π
you're getting one of these:
valkey-protocol(7)Integer reply:1if the timeout was set. slay.valkey-protocol(7)Integer reply:0if the timeout was not set. for example, if the key doesn't exist, or the operation was skipped due to the provided arguments. it's giving "we tried, we didn't" π
π COMPLEXITY π
O(1) β constant time, baby. no sweat, no stress, no cap. π₯
π ACL CATEGORIES π
@fast @keyspace @write
π§ HISTORY π§
- Available since:
2.6.0β an elder, an OG, a legend β¨ - Changed in
7.0.0: added options:NX,XX,GTandLT. glow up fr fr π
π EXAMPLES π
127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> PEXPIREAT mykey 1555555555005
(integer) 1
127.0.0.1:6379> TTL mykey
(integer) -2
127.0.0.1:6379> PTTL mykey
(integer) -2
look at her go π₯Ή set the key, set the expiry, and then both TTL and PTTL come back -2. no notes.
π«Ά SEE ALSO π«Ά
copy(3valkey), del(3valkey), dump(3valkey), exists(3valkey), expire(3valkey), expireat(3valkey), expiretime(3valkey), keys(3valkey), migrate(3valkey), move(3valkey), object(3valkey), object-encoding(3valkey), object-freq(3valkey), object-help(3valkey), object-idletime(3valkey), object-refcount(3valkey), persist(3valkey), pexpire(3valkey), pexpiretime(3valkey), pttl(3valkey), randomkey(3valkey), rename(3valkey), renamenx(3valkey), restore(3valkey), scan(3valkey), sort(3valkey), sort_ro(3valkey), touch(3valkey), ttl(3valkey), type(3valkey), unlink(3valkey), wait(3valkey), waitaof(3valkey)
and that's the whole page bestie!! π this was version 9.0.0, dated 2025-10-21, straight from the PEXPIREAT(3valkey) corner of the Valkey Command Manual. go set some expiries, main character πππ¦
π¦ 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