GETEX(3valkey)

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

✨ 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:

  • EX seconds β€” set that expire time, but in seconds ⏱️
  • PX milliseconds β€” same energy, but in milliseconds 🫢
  • EXAT timestamp-seconds β€” set the exact Unix time the key will expire, in seconds πŸ“…
  • PXAT timestamp-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

RESP3

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