Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

SETEX

Last updated
SETEX key seconds value
Group
String
Complexity
O(1)
Arity
4 (exactly, counting the command name)
Flags
write
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

SETEX stores value at key and makes it expire after seconds, in one step. It is the same as SET key value EX seconds. Any existing value, of any type, is overwritten.

Case RESP2 RESP3
Always Simple string OK Simple string OK

Errors:

  • ERR value is not an integer or out of range when seconds is not an integer.
  • ERR invalid expire time in 'setex' command when seconds is zero, negative or too large.
127.0.0.1:6379> SETEX session:9 600 "user:9"
OK
127.0.0.1:6379> TTL session:9
(integer) 600
127.0.0.1:6379> SETEX session:9 0 "user:9"
(error) ERR invalid expire time in 'setex' command

Same as Redis 7 and Valkey 8.

SET, PSETEX, EXPIRE, MSETEX