EXPIREAT(3valkey)

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

πŸ’– EXPIREAT πŸ’–

okay bestie, so you know how EXPIRE sets a countdown on a key? this is that, but the manual version of a countdown β€” you tell it the exact moment in time when the key should ghost everyone. it's from the valkey command manual, and honestly? it ate. ✨


✨ NAME ✨

expireat β€” sets the expiration time of a key to a Unix timestamp. literally just "hey key, you're expiring at this exact second," no cap. πŸŽ€


🌸 SYNOPSIS 🌸

EXPIREAT key unix-time-seconds [NX | XX | GT | LT]

that's the whole vibe. key, a timestamp in seconds, and optionally one of those four little modifiers. periodt. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So EXPIREAT does the exact same thing, same semantics, as EXPIRE from valkey-expire(7) β€” except instead of handing it a number of seconds that means "TTL, time to live," you hand it an absolute Unix timestamp (that's seconds since January 1, 1970, iykyk). ⏰

And here's the tea: a timestamp that's already in the past will delete the key immediately. like, instantly. no waiting. gone. πŸ’€

For the specific semantics of the command, please go read the documentation of EXPIRE β€” bestie, it's all there, I'm not gonna repeat it. πŸ™ˆ

🌈 Background 🌈

EXPIREAT was introduced so you could convert relative timeouts into absolute timeouts for the AOF persistence mode. that was its whole origin story, main character energy. ✨

And of course you can also just... use it directly, to say "this key expires at this specific time in the future." slay. πŸ‘‘


πŸŽ€ OPTIONS πŸŽ€

The EXPIREAT command supports a set of options:

  • NX β€” Set expiry only when the key has no expiry.
  • XX β€” Set expiry only when the key has an existing expiry.
  • GT β€” Set expiry only when the new expiry is greater than the current one.
  • LT β€” Set expiry only when the new expiry is less than the current one.

A non-volatile key is treated as an infinite TTL for the purpose of GT and LT. and heads up β€” GT, LT and NX are mutually exclusive, so don't try to be greedy and stack them. pick one. πŸ’…


πŸ’œ REPLY πŸ’œ

One of the following, bestie:

  • valkey-protocol(7) Integer reply: 0 if the timeout was not set β€” for example, the key doesn't exist, or the operation was skipped because of the provided arguments. 😭
  • valkey-protocol(7) Integer reply: 1 if the timeout was set. πŸŽ‰

⭐ COMPLEXITY ⭐

O(1)

constant time, baby. iconic. ✨


🌟 ACL CATEGORIES 🌟

@fast @keyspace @write


🧚 HISTORY 🧚

  • Available since: 1.2.0
  • Changed in 7.0.0: Added options: NX, XX, GT and LT.

πŸ”₯ EXAMPLES πŸ”₯

127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> EXISTS mykey
(integer) 1
127.0.0.1:6379> EXPIREAT mykey 1293840000
(integer) 1
127.0.0.1:6379> EXISTS mykey
(integer) 0

see how it goes from 1 to 0? that's the key leaving the group chat. bye bestie πŸ‘‹πŸ’–


πŸ‘‘ SEE ALSO πŸ‘‘

copy(3valkey), del(3valkey), dump(3valkey), exists(3valkey), expire(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), pexpireat(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 a wrap, bestie!! 🌈 this one's from version 9.0.0, dated 2025-10-21 β€” so go forth, set some absolute timestamps, and remember: past timestamps delete your key immediately, so maybe double-check your math before you hit enter. πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from