EXPIRE command in redis

EXPIRE key seconds

This command set a timeout on key. After the timeout has expired, the key will automatically be deleted. A key with an associated timeout is often said to be volatile in Redis terminology.

TIME COMPLEXITY O(1)

RETURN VALUE integer reply, specifically:

1 if the timeout was set.

0 if key does not exist or the timeout could not be set.

Syntax:

EXPIRE KEY_NAME TIME_IN_SECONDS

Example 1: When the key is present

redis:6379> EXPIRE  redisKey 100
(integer) 1

Output

1


Example: When the key is not present

redis:6379> EXPIRE redis 1010
(integer) 0

Output

0

No comments:

Post a Comment