SETEX · Valkey

SETEX

Sets the string value and expiration time of a key. Creates the key if it doesn’t exist.

Usage

SETEX key seconds value

Description

Set key to hold the string value and set key to timeout after a given number of seconds. This command is equivalent to:

SET key value EX seconds

An error is returned when seconds is invalid.

Alternative

SET with the EX argument.

Reply

Simple string reply: OK.

Complexity

O(1)

ACL Categories

@slow @string @write

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 also

TTL

History

See also

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