SETEX command in redis

SETEX key seconds value

Set key to hold the string value and set key to timeout after a given number of seconds.

This command is equivalent to executing the following commands:

SET mykey value

EXPIRE mykey seconds

COMPLEXITY O(1)

SETEX is atomic and can be reproduced by using the previous two commands inside a MULTI / EXEC block. It is provided as a faster alternative to the given sequence of operations because this operation is very common when Redis is used as a cache.

Note: An error is returned when seconds are invalid.

RETURN VALUE Status reply

Syntax:

SETEX key seconds value

Example 1: When the seconds are valid.

redis:6379> SETEX myKey 1000 hello
"OK"

Output

OK


Example 2: When the seconds are invalid

redis:6379> SETEX myKey hello 1000
(error) value is not an integer or out of range

Output

(error) value is not an integer or out of range


No comments:

Post a Comment