Redis and Memcached are both in-memory key-value stores used for caching, but they differ significantly in capability. Memcached is a simple, high-performance cache with a focused feature set. Redis is a versatile data structure server that supports persistence, pub/sub, scripting, and rich data types beyond simple strings. Your choice depends on whether you need a pure cache or a multi-purpose in-memory data store.
| Feature | Redis | Memcached |
|---|---|---|
| Data structures | Strings, lists, sets, sorted sets, hashes, streams, bitmaps | Strings only |
| Max value size | 512 MB | 1 MB (default) |
| Persistence | RDB snapshots + AOF log | None (pure cache) |
| Threading | Single-threaded (I/O threads in 6.0+) | Multi-threaded |
| Pub/Sub | Built-in with channels and patterns | Not supported |
| Scripting | Lua scripts and Redis Functions | Not supported |
| Clustering | Redis Cluster (automatic sharding) | Client-side sharding (consistent hashing) |
| Memory efficiency | Higher overhead per key (metadata) | Lower overhead (slab allocator) |
How do data structures affect use cases?
Memcached stores only string key-value pairs, so any complex data must be serialized by the client. Redis natively supports lists (queues, feeds), sets (unique collections, tagging), sorted sets (leaderboards, rate limiting), hashes (object storage), and streams (event logs). These server-side data structures enable atomic operations — for example, incrementing a counter, adding to a sorted set, or popping from a queue — without client-side read-modify-write cycles.
Does persistence matter for a cache?
For a pure cache, persistence is optional — a cold restart just means cache misses until the cache warms up. But Redis is often used beyond caching: as a session store, job queue, leaderboard, or rate limiter. In these cases, persistence (RDB snapshots for point-in-time recovery, AOF for durability) prevents data loss on restarts. Memcached has no persistence, so all data is lost when the process restarts, limiting it to disposable cache workloads.
Which handles more concurrent connections?
Memcached's multi-threaded architecture can utilize multiple CPU cores, giving it an advantage with many concurrent connections performing simple GET/SET operations. Redis is single-threaded for command execution (ensuring atomicity), though Redis 6.0+ added I/O threading for network handling. In practice, a single Redis instance handles 100,000+ operations per second, and you can scale horizontally with Redis Cluster. Memcached may outperform Redis only under extremely high connection counts with simple operations.
How do eviction strategies compare?
Both support LRU (Least Recently Used) eviction when memory is full. Redis offers more policies: volatile-lru (evict only keys with TTL), allkeys-lfu (Least Frequently Used), volatile-ttl (evict keys closest to expiration), and noeviction (return errors when full). Memcached uses a slab-based LRU, which can lead to memory fragmentation — large items may be evicted even when small-item slabs have free space. Redis uses a sampling-based approximation of LRU/LFU that is more memory-efficient.
When to use which?
Choose Redis when you need data structures beyond strings, persistence, pub/sub messaging, Lua scripting, or transactions. Redis is the right choice for session stores, job queues, real-time leaderboards, rate limiting, and any scenario where you need more than a simple cache. It is the default recommendation for most applications.
Choose Memcached when you need a simple, multi-threaded cache for string key-value pairs with minimal operational complexity. Memcached is a good fit when you're caching serialized objects or HTML fragments, don't need persistence, and want predictable memory usage with its slab allocator. It remains popular in legacy PHP applications and large-scale web caching tiers.
Key takeaways
- Redis supports rich data structures (lists, sets, sorted sets, streams); Memcached is strings only
- Redis offers persistence, pub/sub, scripting, and transactions — making it a data platform, not just a cache
- Memcached is multi-threaded and can handle more concurrent connections for simple GET/SET operations
- Redis is the default choice for new applications; Memcached when you need a pure, simple cache
- Both deliver sub-millisecond latency and handle hundreds of thousands of operations per second