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
2009 — Salvatore Sanfilippo creates Redis for his startup, LLOOGG.
2010 — VMware hires Sanfilippo; Redis is sponsored.
2015 — Redis Cluster (native sharding) is released.
2020 — Redis Labs renames itself Redis; the license changes to RSALv2/SSPL.
2021 — The Redis fork "Valkey" is created by AWS, Google, Oracle due to license concerns.
How to use Redis well
Redis best practices
Set maxmemory-policy
allkeys-lrufor caches,noevictionfor persistent data. Never let Redis OOM.Use specific data types
Sorted sets for leaderboards, hashes for objects, lists for queues. Don't store JSON strings if a hash fits.
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.
Cluster for scale
Single Redis node is ~100 GB RAM max. Above that, use Redis Cluster to shard across nodes.
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
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
- cache
- memcached
- in-memory-database
- pub-sub
Redis (2024). Redis documentation. https://redis.io/docs/
Redis (2024). Redis persistence. https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/
Redis (2024). Redis cluster specification. https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec/
GitHub (2024). redis/redis. https://github.com/redis/redis
Etymology
Origin: acronym
RE(noun): RemoteDI(noun): DictionaryS(noun): Server
Semantic network
● broader ● narrower ● related
Used in the garden
- The DBA-Free Playbook: Unlocking MySQL's Hidden Power for Your SaaS (2×)
- Architecting API Dominance: Design a REST API That Scales From Day One (1×)
- Technical SEO, Core Web Vitals, and Mobile SEO: The Complete Guide (1×)
- Mastering Content Curation: Build Your Own RSS Aggregator with PHP & SimplePie (1×)
- The Zero-Downtime WordPress Migration Blueprint for High-Stakes Sites (1×)
- Unlock Real-Time Power: Vanilla JS & SSE for Elite Dashboards (1×)
Sources
Redis (2024). Redis documentation. https://redis.io/docs/
GitHub (2024). redis/redis. https://github.com/redis/redis