Redis lets keys expire automatically after a set time (TTL — Time To Live) — after which they're deleted. This is fundamental for caching (expiring stale data), sessions, and any temporary data, and is one of Redis's most-used features.
Setting expiration
SET session:abc EX 3600
SET key PX 5000
SET cache:user:1
EXPIRE cache:user:1 300
EXPIREAT key 1735689600
