English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Expire Command

Redis Key (Key)

The Redis Expire command is used to set the expiration time of the key, and the key will no longer be available after expiration. The unit is in 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

Setting successful returns 1 . When the key does not exist or cannot set an expiration time for the key (for example, in versions lower than 2.1.3 If you try to update the expiration time of the key in a version of Redis lower than

Online Examples

First, create a key and assign a value:

redis 127.0.0.1:6379> SET runooobkey redis
OK

Set expiration time for key:

redis 127.0.0.1:6379> EXPIRE runooobkey 60
(integer) 1

In the above example, we set the expiration time for the key runooobkey to 1 minute,1The key will be automatically deleted after one minute.

Redis Key (Key)