setex.3valkey - Man Page

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

Synopsis

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

valkey-protocol(7) Simple string reply: OK.

Complexity

O(1)

Acl Categories

@slow @string @write

History

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

See Also

append(3valkey), decr(3valkey), decrby(3valkey), delifeq(3valkey), get(3valkey), getdel(3valkey), getex(3valkey), getrange(3valkey), getset(3valkey), incr(3valkey), incrby(3valkey), incrbyfloat(3valkey), lcs(3valkey), mget(3valkey), mset(3valkey), msetnx(3valkey), psetex(3valkey), set(3valkey), setnx(3valkey), setrange(3valkey), strlen(3valkey), substr(3valkey)

Info

2025-10-21 9.0.0 Valkey Command Manual