getex.3valkey - Man Page

Returns the string value of a key after setting its expiration time.

Synopsis

GETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST]

Description

Get the value of key and optionally set its expiration. GETEX is similar to GET, but is a write command with additional options.

Options

The GETEX command supports a set of options that modify its behavior:

Reply

Resp2

valkey-protocol(7) Bulk string reply: the value of key

valkey-protocol(7) Nil reply: if key does not exist.

Resp3

valkey-protocol(7) Bulk string reply: the value of key

valkey-protocol(7) Null reply: if key does not exist.

Complexity

O(1)

Acl Categories

@fast @string @write

History

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 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), msetex(3valkey), msetnx(3valkey), psetex(3valkey), set(3valkey), setex(3valkey), setnx(3valkey), setrange(3valkey), strlen(3valkey), substr(3valkey)

Info

2026-05-19 9.1.0 Valkey Command Manual