SETEX(3valkey)
π SETEX β the "set it and β¨time it outβ¨" command (3valkey)
okay bestie, imagine you wanna set a key AND have it self-destruct after a bit. that's this. no cap.
β¨ NAME β¨
setex β sets the string value and the expiration time of a key. creates the key if it doesn't exist. like, it's giving "here's your value, and also a countdown timer, you're welcome" π
πΈ SYNOPSIS πΈ
SETEX key seconds value
π¦ DESCRIPTION π¦
so the whole vibe is: set key to hold the string value, and set key to time out after a given number of seconds. this command is literally equivalent to:
SET key value EX seconds
an error gets returned when seconds is invalid. like, don't try anything funny with that number, the server WILL clock it. π
π Alternative
just use SET with the EX argument. same energy, different outfit.
π REPLY π
valkey-protocol(7) Simple string reply: OK.
β COMPLEXITY β
O(1) β constant time, we love a low-effort queen.
π ACL CATEGORIES π
@slow @string @write
π HISTORY π
- available since: 2.0.0 β a true legacy icon, been here since forever fr fr
π EXAMPLES π
127.0.0.1:6379> SETEX mykey 10 "Hello"
OK
127.0.0.1:6379> TTL mykey
(integer) 10
127.0.0.1:6379> GET mykey
"Hello"
see how the TTL is sitting at 10? and then GET still hands you back "Hello"? that's the whole magic trick, bestie. ate. π₯
π SEE ALSO π
TTL
π§ SEE ALSO π§
append(3valkey), decr(3valkey), decrby(3valkey), delifeq(3valkey), get(3valkey), getdel(3valkey), getex(3valkey), getrange(3valkey), getset(3valkey), incr(3valkey), incrby(3valkey), incrbyfloat(3valkey), lcs(3valkey), mget(3valkey), mset(3valkey), msetnx(3valkey), psetex(3valkey), set(3valkey), setnx(3valkey), setrange(3valkey), strlen(3valkey), substr(3valkey)
lowkey a whole friend group of string commands up there. go say hi. π«Ά
and that's the tea, bestie π this page is from the Valkey 9.0.0 manual, dated 2025-10-21, and honestly? iconic. periodt. β¨ππ
π¦ 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