Redis

Redis (Remote Dictionary Server) is an in-memory data-structure store. By keeping data in RAM, it serves reads and writes in microseconds, and it offers far more than plain key-value: strings, hashes, lists, sets, sorted sets, and streams, each with purpose-built commands.

Most often Redis sits beside your primary database as a cache or for ephemeral data — sessions, rate-limit counters, queues, leaderboards — where speed matters and the data is short-lived or reconstructable.

TL;DR

Quick Example

The canonical cache pattern — store a value with a time-to-live so it expires automatically:

Core Concepts

Common Uses

Best Practices

Comparison: Redis vs Memcached

Common Mistakes

Caching without a TTL

Treating Redis as a durable database by default

FAQ

Is Redis a cache or a database?

Both, but most often a cache or store for ephemeral data. It can be a primary database with persistence (RDB/AOF) enabled, but it's typically paired with a durable store like PostgreSQL, holding hot or short-lived data.

How does persistence work?

RDB takes periodic point-in-time snapshots (compact, fast restore, but you can lose recent writes). AOF logs every write for better durability at some performance cost. You can use either, both, or neither depending on how much data loss you can tolerate.

Why is a single-threaded store so fast?

Redis avoids lock contention and context-switching by handling commands on one thread, using non-blocking I/O multiplexing to juggle many connections. Since operations are in-memory and O(1)/O(log n), the thread is rarely the bottleneck.

Redis or Memcached?

Memcached for a dead-simple string cache. Redis for everything else — richer data structures, optional persistence, pub/sub, TTLs, and atomic operations make it the more versatile default.

Related Topics

References