Redis Expire command is used to set the expiry of a key. After the expiry time, the key will not be available in Redis.
Return Value
Integer value 1 or 0
- 1, if timeout is set for the key.
- 0, if the key does not exist or timeout could not be set.
Syntax
Following is the basic syntax of Redis Expire command.
redis 127.0.0.1:6379> Expire KEY_NAME TIME_IN_SECONDS
Example
First, create a key in Redis and set some value in it.
redis 127.0.0.1:6379> SET Adglob redis OK
Now, set timeout of the previously created key.
redis 127.0.0.1:6379> EXPIRE Adglob 60 (integer) 1
In the above example, 1 minute (or 60 seconds) time is set for the key Adglob. After 1 minute, the key will expire automatically.