EXPIREAT(3valkey)
π 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:0if 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:1if 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,GTandLT.
π₯ 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
- 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