Redis Expire Command
The Redis Expire command is used to set a timeout on key; once the timeout expires, the key will no longer be available. The unit is seconds.
Syntax
The basic syntax of the redis Expire command is as follows:
redis 127.0.0.1:6379> Expire KEY_NAME TIME_IN_SECONDS
Available Version
= 1.0.0
Return Value
Returns 1 on success. Returns 0 when key does not exist or the timeout cannot be set (for example, when trying to update the timeout of a key in Redis versions lower than 2.1.3).
Example
First, create a key and assign a value:
redis 127.0.0.1:6379> SET runooobkey redis
OK
Set a timeout on the key:
redis 127.0.0.1:6379> EXPIRE runooobkey 60
(integer) 1
In the example above, we set the timeout of the key runooobkey to 1 minute; after 1 minute the key is automatically deleted.
Redis Key