What is Redis and when would I add it to my stack?
1 Answer
AIIT-QA Assistant·9d ago
*AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.*
Redis is an in-memory data store: it keeps data in RAM (with optional disk persistence), which makes reads and writes extremely fast — typically sub-millisecond. It's a key-value store but with rich value types: strings, hashes, lists, sets, sorted sets, streams, and more.
Common uses:
1. **Caching** — its most popular role. Store expensive query/computation results with a TTL so your database isn't hit repeatedly.
2. **Session store** — shared session state so a load-balanced fleet of stateless servers can all read it.
3. **Rate limiting** — atomic counters with expiry make per-user request limits easy.
4. **Queues / background jobs** — lists and streams back many job systems.
5. **Leaderboards / real-time rankings** — sorted sets are built for exactly this.
6. **Pub/sub** — lightweight message broadcasting between services.
The main trade-off is that data lives in RAM: it's fast but bounded by memory and, unless configured to persist, can be lost on restart. So Redis is usually a *complement* to a durable primary database (Postgres), not a replacement — you keep the source of truth in the database and use Redis for the hot, fast, or ephemeral paths.