Redis is a more versatile in-memory data store, while Memcached is a simpler pure cache. Both achieve sub-millisecond latencies, but Redis offers data structures, persistence, and advanced features that make it more than just a cache. Memcached remains relevant for specific scenarios where its simplicity and multi-threaded architecture provide an advantage.
Redis¶
- Data structures — strings, lists, sets, sorted sets, hashes, streams, bitmaps, HyperLogLog
- Persistence — RDB snapshots (periodic) and AOF (append-only file for point-in-time recovery)
- Pub/Sub and Streams — real-time messaging and event streaming without an external message broker
- Lua scripting — atomic server-side operations for complex logic
- Cluster and Sentinel — horizontal scaling and automatic failover
- Single-threaded event loop — every command is atomic, no race conditions
Redis with data structures enables implementing leaderboards (sorted sets), rate limiters (INCR + EXPIRE), session storage (hashes), queues (lists/streams), and distributed locks — all in one system with sub-millisecond latency.
Memcached¶
- Key-value only — only string keys and values, no complex structures
- No persistence — restart = loss of all data
- Multi-threaded — utilizes multiple CPU cores, better for simple operations on multi-core servers
- Simpler — less memory per key, lower overhead, fewer features = fewer bugs
- No advanced features — no pub/sub, scripting, or cluster management
Memcached is single-purpose — a pure cache with the lowest possible latency and minimal overhead. For large volumes of simple get/set operations, it can be faster than Redis due to its multi-threaded architecture.
When to Use Which¶
- Redis — sessions, leaderboards, rate limiting, queues, pub/sub, cache with persistence, general in-memory data store
- Memcached — pure caching of large volumes of simple key-value pairs, multi-threaded advantage on multi-core servers
Redis for 95% of Use Cases¶
Redis is more versatile and covers most needs. Choose Memcached only for pure caching of large volumes where you need maximum throughput of simple get/set operations and do not need persistence or data structures.