EXPIRE / TTL

EXPIRE sets a timeout on a key in seconds. After the timeout, the key is automatically deleted. TTL returns the remaining time to live. PERSIST removes the expiry.

Syntax

redis
EXPIRE key seconds
TTL key
PERSIST key

Example

redis
SET token "abc123"
EXPIRE token 900
TTL token
# (integer) 900
PERSIST token
TTL token
# (integer) -1 (no expiry)