Introduction
Redis is an in-memory data store: it keeps data in RAM instead of on disk, which makes it roughly a hundred times faster than a disk database for simple operations β but also means it is not where your permanent data should live alone. Redis is the accelerator you bolt onto a real database, and it powers caching, sessions, leaderboards, and queues across the modern web.
Caching: the job Redis is famous for
The most common Redis job is caching: storing the result of an expensive database query so the next request doesn't repeat it.
User requests homepage β Check Redis for "homepage:en" β Found? Return it instantly (milliseconds) β Not found? Query Postgres, store the result in Redis with a 60-second expiry, return it
Enter fullscreen mode
Exit fullscreen mode
Expiry is the key idea: cached data gets a time-to-live ( TTL ), after which Redis deletes it and the next request refreshes it from the real database.β¦