GETEX · Valkey

GETEX

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

Usage

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

String: the value of key

Null: if key does not exist.

Complexity

O(1)

ACL Categories

@fast @string @write

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

History

See also

APPEND, DECR, DECRBY, DELEX, DELIFEQ, GET, GETDEL, GETRANGE, GETSET, INCR, INCRBY, INCRBYFLOAT, INCREX, LCS, MGET, MSET, MSETEX, MSETNX, PSETEX, SET, SETEX, SETNX, SETRANGE, STRLEN, SUBSTR.