Skip to content

Redis

Redis is an open-source, in-memory data structure store used as a database, cache, message broker and queue; it stores data in RAM for microsecond latency and offers persistence, replication and clustering.

Definition

What it is

Redis is a key-value store that lives in memory. Unlike a traditional database that reads from disk, Redis keeps the entire dataset in RAM, achieving microsecond-level reads and writes. It is used primarily as a cache, but it is also a message broker (Pub/Sub), a queue (with blocking operations), a leaderboard (sorted sets), and a session store.

Redis is single-threaded for command execution, using an event loop. This sounds slow, but it is the source of its safety guarantees: no two commands run concurrently, so no locking is needed. Redis 6 introduced I/O threading for reading/writing, but commands remain single-threaded.

Why it matters

A database query takes 10–100 ms. A Redis GET takes 0.1–1 ms. For a homepage that renders 20 database queries, moving the hot ones to Redis drops the page load from 500 ms to 50 ms. For high-traffic sites, Redis is the difference between a database that scales and one that melts.

Redis vs Memcached vs traditional DB

Aspect

Redis

Memcached

Traditional DB

Storage

RAM + disk (optional)

RAM only

Disk

Data types

Strings, lists, sets, hashes

Strings

Full SQL

Latency

Sub-ms

Sub-ms

10-100 ms

Persistence

RDB / AOF

None

Full

Pub/Sub

Yes

No

No

Cluster

Yes

Yes (limited)

Yes

The Redis architecture

graph LR
  C[Client] -->|command| R[Redis]
  R -->|read/write| M[Memory]
  R -->|persist| D[Disk - RDB/AOF]
  R -->|response| C
  style R fill:#E8F5E9

Timeline

  1. 2009 — Salvatore Sanfilippo creates Redis for his startup, LLOOGG.

  2. 2010 — VMware hires Sanfilippo; Redis is sponsored.

  3. 2015 — Redis Cluster (native sharding) is released.

  4. 2020 — Redis Labs renames itself Redis; the license changes to RSALv2/SSPL.

  5. 2021 — The Redis fork "Valkey" is created by AWS, Google, Oracle due to license concerns.

How to use Redis well

Redis best practices

  1. Set maxmemory-policy

    allkeys-lru for caches, noeviction for persistent data. Never let Redis OOM.

  2. Use specific data types

    Sorted sets for leaderboards, hashes for objects, lists for queues. Don't store JSON strings if a hash fits.

  3. Persistence is not backup

    RDB and AOF help with restart time, not with data loss. If Redis dies, you lose data written since the last snapshot.

  4. Cluster for scale

    Single Redis node is ~100 GB RAM max. Above that, use Redis Cluster to shard across nodes.

  5. Pub/Sub for ephemeral, Streams for durable

    Pub/Sub loses messages if no subscriber is connected. Streams is the durable alternative.

Common failures

Origin

Salvatore Sanfilippo (antirez) built Redis in 2009 to solve a scaling problem in his startup LLOOGG. He needed a real-time analytics engine that could handle high write throughput. The name is a backronym: REmote DIctionary Server. Redis is now maintained by Redis Ltd. (formerly Redis Labs).

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker.

— Redis documentation, 2024
2009 · Salvatore Sanfilippo crea Redis
2015 · Redis Cluster nativo
2021 · Valkey (fork) por AWS/Google/Oracle
1M+ · ops/s en un solo nodo en hardware moderno

Evidence

FAQ

Redis vs Memcached?

Redis has data structures, persistence, and Pub/Sub. Memcached is a pure cache with strings only.

Does Redis persist data?

Yes, via RDB (snapshots) and AOF (append-only file). It is not a backup; use it for restart speed.

How does Redis scale?

Redis Cluster shards data across nodes. Single-node Redis is limited by RAM.

Is Redis single-threaded?

Command execution is single-threaded. I/O is threaded in Redis 6+.

Connections

Etymology

Origin: acronym

  • RE (noun): Remote
  • DI (noun): Dictionary
  • S (noun): Server

Semantic network

Redisdata-storecachingCacheMemcachedIn-memory pub-sub

● broader ● narrower ● related

Broader

  • data-stores
  • caching

Related

Used in the garden

Sources