Redis Architecture and Data Structures
You'll learn how Redis organizes data in memory, persists it to disk, and leverages specialized data structures for ultra-fast caching.
What is Redis?
Redis (Remote Dictionary Server) is an in-memory data store often used as a cache or message broker. Unlike traditional databases that read from disk, Redis keeps everything in RAM for microsecond-level access times — think of it as a highly organized filing cabinet in your brain rather than in a warehouse.
Architecture Overview
Redis runs as a single-threaded process (one command at a time), which eliminates lock contention but still handles tens of thousands of operations per second. It supports two persistence models:
- RDB (snapshots): Periodic dumps of the entire dataset to disk — fast recovery, but you might lose recent writes
- AOF (append-only file): Logs every write operation — more durable but slower and larger files
You can combine both for reliability.
Core Data Structures
Redis isn't just key-value; it's a data structure server:
- Strings: Simple key-value pairs (
SET user:123 "Alice") - Hashes: Objects with fields (
HSET user:123 name "Alice" age 30) — perfect for storing user profiles or session data - Lists: Ordered collections (
LPUSH queue task1) — ideal for message queues or activity feeds - Sets: Unique, unordered elements — great for tags or membership checks
- Sorted Sets: Sets with scores for ranking and leaderboards
Each structure has optimized commands (HGET, LPOP, ZADD) that operate atomically without needing complex queries.
Why It Matters
Choosing the right data structure dramatically impacts performance. A hash uses less memory than storing each field as a separate string key, while lists enable efficient queue operations that would require multiple operations in a traditional key-value store.
Key Takeaway:
Redis combines in-memory speed with versatile data structures and configurable persistence, making it the go-to choice for caching, session storage, and real-time features when milliseconds matter.