When would you pick Redis over Memcached for a cache?
Memcached is a simple, fast key-value cache. Redis adds data structures (lists, sets, sorted sets), optional persistence, replication and pub/sub, so choose Redis when you need more than plain get and set.
Explain it simply
Both keep data in memory for very fast reads. The difference is how much they do.
Memcached: strings only, multi-threaded, very simple to run. Fine for caching rendered pages or query results where you just get and set blobs. No persistence; restart means an empty cache.
Redis: values can be strings, hashes, lists, sets, sorted sets and more. That unlocks uses beyond caching:
- Leaderboard with a sorted set (a cricket fantasy ranking).
- Rate limiter using atomic counters with expiry.
- Session store, with TTL per key.
- Queues and pub/sub for lightweight messaging.
- Optional persistence (snapshots, append-only log) and replication with failover.
Redis executes commands on one main thread, which keeps operations atomic and simple, while Memcached can use many cores for pure throughput on simple keys.
If all you do is cache plain objects, either works. Many teams default to Redis because it covers more needs with one tool.
Example
A fantasy-cricket leaderboard:
ZADD board 4520 "asha"
ZADD board 4710 "ravi"
ZADD board 4390 "meera"
ZREVRANGE board 0 1 -> ravi, asha (top 2)Doing this on Memcached would mean fetching the whole list, sorting in the app, and writing it back.
What to say in the interview
"Memcached for the simplest, highest-throughput object caching. Redis when I need data structures, TTL control, persistence or replication, such as leaderboards, counters and sessions. Because Redis serves many roles, I often start with it."