0Pricing
Caching Strategies: Redis + CDN + Edge Computing · Lesson

TTL and Expiration in Redis

Learn how Redis handles key expiration: setting TTLs, the EXPIRE and SETEX commands, how lazy and active expiry work, and how the maxmemory eviction policies interact with TTLs.

Why Expire Cache Keys?

Cached data goes stale. Time To Live (TTL) lets Redis automatically remove a key after a set duration, so your cache stays reasonably fresh without manual cleanup.

Setting a TTL with EXPIRE

The EXPIRE command sets a timeout in seconds on an existing key. After that time, Redis deletes the key automatically.

SET user:1 "Alice"
EXPIRE user:1 60
TTL user:1

All lessons in this course

  1. Introduction to Redis Caching
  2. Redis Data Structures for Cache
  3. Basic Redis Cache Operations
  4. TTL and Expiration in Redis
← Back to Caching Strategies: Redis + CDN + Edge Computing