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.

Reply

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

Complexity

O(1)

Acl Categories

@slow @string @write

History

Notes

This command is deprecated (since 2.6.12) and replaced by SET with the EX argument.

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), get(3valkey), getdel(3valkey), getex(3valkey), getrange(3valkey), incr(3valkey), incrby(3valkey), incrbyfloat(3valkey), lcs(3valkey), mget(3valkey), mset(3valkey), msetnx(3valkey), set(3valkey), setrange(3valkey), strlen(3valkey)

Info

2024-09-23 8.0.0 Valkey Command Manual