GETEX(3valkey)
β¨ GETEX π
okay bestie so this is a page from the Valkey Command Manual (that's the 3valkey manual, if you're keeping track) and it's literally all about GETEX. sit down, hydrate, let's go πΈ
π NAME
getex β grabs the string value of a key and also sets its expiration time. two things, one command, main character energy π
π SYNOPSIS
GETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT
unix-time-milliseconds | PERSIST]
that bracket situation means you get one of those options, or none at all. no mixing and matching, bestie π
π¦ DESCRIPTION
So the whole vibe is: get the value of key, and optionally set its expiration while you're at it. GETEX is giving very much like GET, but plot twist β it's a write command with extra options on top. like GET went to college β¨
π OPTIONS
GETEX supports a little set of options that change how it behaves, and here they all are:
EXsecondsβ set that expire time, but in seconds β±οΈPXmillisecondsβ same energy, but in milliseconds π«ΆEXATtimestamp-secondsβ set the exact Unix time the key will expire, in seconds πPXATtimestamp-millisecondsβ exact Unix time it expires, but in milliseconds π«PERSISTβ remove the time to live that's attached to the key. no more expiry, it lives forever (well, until you say otherwise) π
π REPLY
RESP2
valkey-protocol(7)Bulk string reply: the value ofkeyvalkey-protocol(7)Nil reply: ifkeydoes not exist π
RESP3
valkey-protocol(7)Bulk string reply: the value ofkeyvalkey-protocol(7)Null reply: ifkeydoes not exist π
ngl the only difference between RESP2 and RESP3 here is "Nil" vs "Null". same heartbreak, different label π
β COMPLEXITY
O(1) β constant time, no cap. she's fast, she's efficient, she ate π₯
π ACL CATEGORIES
@fast @string @write
π§ HISTORY
- Available since: 6.2.0 β an icon from the start, fr fr
π EXAMPLES
127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> GETEX mykey
"Hello"
127.0.0.1:6379> TTL mykey
(integer) -1
127.0.0.1:6379> GETEX mykey EX 60
"Hello"
127.0.0.1:6379> TTL mykey
(integer) 60
see how the first TTL is -1 (no expiry, free spirit) and after GETEX mykey EX 60 it's 60? that's the write part doing its thing. obsessed π
π₯ SEE ALSO
append(3valkey), decr(3valkey), decrby(3valkey), delifeq(3valkey), get(3valkey), getdel(3valkey), getrange(3valkey), getset(3valkey), incr(3valkey), incrby(3valkey), incrbyfloat(3valkey), lcs(3valkey), mget(3valkey), mset(3valkey), msetnx(3valkey), psetex(3valkey), set(3valkey), setex(3valkey), setnx(3valkey), setrange(3valkey), strlen(3valkey), substr(3valkey)
the whole friend group, go say hi π«Ά
and that's the whole page bestie β¨ this was GETEX from version 9.0.0, dated 2025-10-21, living in the GETEX(3valkey) corner of the manual. go set some expirations, you got this π
π
π¦ 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