PEXPIREAT(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– 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, iykyk
  • GT β€” set the expiry only when the new expiry is greater than the current one
  • LT β€” 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 of GT and LT. and GT, LT and NX are mutually exclusive β€” pick your fighter, you cannot have all three 😭

🌈 REPLY 🌈

you're getting one of these:

  • valkey-protocol(7) Integer reply: 1 if the timeout was set. slay.
  • valkey-protocol(7) Integer reply: 0 if 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, GT and LT. 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