Redis vs Memcached: differences and which to choose
Both are in-memory caches. Memcached does one thing simply; Redis is a data-structure server that also caches.
By devskills editorial team · Last updated
What problem does the Redis vs Memcached choice solve?
"Put Redis in front of it" has become a reflex, and interviewers sometimes ask why not Memcached. The honest answer is that for a plain look-aside cache of strings, both work, and the choice comes down to what else you need.
Memcached stores opaque values by key, across many threads, and nothing more. Redis stores typed data structures, can persist and replicate them, and runs scripts against them. That extra power is why Redis gets used for rate limiters, queues and leaderboards, not just caching.
What the Redis vs Memcached choice costs you
When to reach for the Redis vs Memcached choice, and when not to
Use it when
- Memcached: a pure cache of serialised objects or HTML fragments, sharded by the client, where a lost node only means misses.
- Redis: anything that needs data structures or atomic operations on the server: counters, rate limits, sorted leaderboards, sets, streams.
- Redis: when cached data should survive a restart or fail over to a replica.
Do not, when
- Do not choose Redis for its persistence and then treat it as the system of record without understanding what its persistence settings can lose.
- Do not choose Memcached when you will soon need anything beyond get, set, delete and increment; you will end up adding Redis as well.
How the Redis vs Memcached choice actually works
- —Keys and opaque values (1 MB item limit by default, configurable).
- —Multithreaded: one big node uses all its cores.
- —No persistence and no built-in replication; clients shard keys across nodes.
- —Evicts least-recently-used items when full, by default. A pure cache by design.
- —Strings, hashes, lists, sets, sorted sets, streams, bitmaps, HyperLogLog, geo.
- —Commands execute on a main thread; optional I/O threads help with network work.
- —Persistence (RDB snapshots, AOF log), replicas, Sentinel failover, Redis Cluster sharding.
- —Eviction policy is configurable; the default is noeviction, which rejects writes when memory is full.
Data model. Memcached maps a key to a blob of bytes; your application serialises and deserialises. Redis understands types, so it can increment a field inside a hash, add to a sorted set and fetch the top ten, or pop from a list, all atomically on the server without reading the value back.
Threading. Memcached is multithreaded, so a single large node scales with its cores. Redis executes commands one at a time on a main thread, which is what makes each command atomic and makes Lua scripts and MULTI/EXEC transactions simple to reason about. Since Redis 6, optional I/O threads take over socket reads and writes. To use many cores for commands, you run more Redis processes, usually as a cluster.
Persistence and replication. Memcached has neither built in; a restarted node is empty, and high availability means the client tolerates misses. Redis offers RDB snapshots, an append-only file (AOF) with a configurable fsync policy, asynchronous replicas, Sentinel for automatic failover and Redis Cluster for sharding across 16,384 hash slots. Asynchronous replication means a failover can lose the last writes acknowledged by the old primary, which matters if Redis holds anything you cannot rebuild.
Eviction. Memcached evicts least-recently-used items when memory is full, by default (the -M flag makes it return errors instead); evicting is its job. Redis lets you choose: allkeys-lru, allkeys-lfu, the volatile-* policies that only evict keys with a TTL, or noeviction, the default, which returns errors on writes when memory is full. For a cache, set an eviction policy explicitly; for anything else, monitor memory.
Licensing and Valkey. Memcached is BSD-licensed. Redis was BSD-licensed until March 2024, when Redis Ltd. moved new versions to a source-available dual licence (RSALv2 and SSPLv1). The Linux Foundation then started Valkey, a fork of Redis 7.2.4 under the BSD licence, which several cloud providers now offer. Redis 8 added the AGPLv3 as a third licence option. For most teams using a managed service this changes little, but it matters if you embed or redistribute it, so check the licence of the exact version you run.
When Memcached still wins. A very large, simple cache of rendered pages or serialised objects, where multithreading lets a few big nodes replace many Redis processes, and where losing a node only costs misses. Some of the largest published caching deployments, such as the one described in Facebook's memcache paper, are built this way.
| Memcached | Redis | |
|---|---|---|
| Data model | Key to opaque bytes | Key to typed structures (strings, hashes, lists, sets, sorted sets, streams and more) |
| Max value size | 1 MB by default (configurable) | 512 MB per string |
| Threads | Multithreaded | Commands on a main thread; optional I/O threads |
| Persistence | None built in | RDB snapshots and/or AOF log |
| Replication and failover | None built in; client-side sharding | Async replicas, Sentinel, Redis Cluster |
| Eviction | LRU by default | Configurable; default noeviction |
| Server-side logic | Get, set, add, cas, incr/decr | Lua scripts, functions, MULTI/EXEC transactions |
| Pub/sub, queues | No | Pub/sub, lists as queues, streams with consumer groups |
| Licence | BSD | RSALv2/SSPLv1, plus AGPLv3 from Redis 8; Valkey fork is BSD |
# leaderboard: a sorted set keeps scores ordered for youZADD game:42 1500 asha 1320 ben 1710 chenZREVRANGE game:42 0 2 WITHSCORES # top three, highest first# fixed-window rate limit: atomic increment plus expiryINCR rl:user:7:202610261405EXPIRE rl:user:7:202610261405 60# a field inside an object, without reading it backHINCRBY cart:99 sku-123 1- Saying Redis is "multithreaded now" without qualification. I/O threads exist; commands still execute one at a time.
- Leaving Redis on the default noeviction policy and using it as a cache, then getting write errors when memory fills.
- Treating Redis replication as durable. It is asynchronous, so a failover can drop acknowledged writes.
The follow-up an interviewer will ask about the Redis vs Memcached choice
"Why Redis and not Memcached for this cache?"
For the cache alone, either would do, and I would say so. Both are in-memory, sub-millisecond, and support the get, set and TTL I need for cache-aside. I am choosing Redis because the same design also needs a rate limiter and a leaderboard: an atomic increment with an expiry per user per minute, and a sorted set for the top scores. With Memcached I would implement both in application code with read, modify and compare-and-set loops, or run Redis anyway. The costs I accept: Redis executes commands on one main thread per process, so I scale it by sharding rather than with bigger machines, and its replication is asynchronous, so I treat everything in it as rebuildable. I would also set an explicit eviction policy, because the default refuses writes when memory fills, which is the wrong behaviour for a cache.
Redis vs Memcached: common questions
Is Redis faster than Memcached?
For simple get and set, both answer in well under a millisecond inside a data centre, and the network usually dominates. Memcached can use more cores on one node; Redis is scaled out with more processes. Pick on features, then benchmark your own workload.
What is Valkey?
An open-source (BSD) fork of Redis 7.2.4, created under the Linux Foundation in 2024 after Redis changed its licence. It is wire-compatible with Redis for the commands that existed at the fork, and several cloud providers offer it as a managed service.
Can Memcached persist data?
Not as a database would. It is designed as a cache, and a restarted node normally starts empty. Treat any data in it as something you can reload from the source of truth.
Should I use Redis as my primary database?
Only if you have configured persistence and replication for the loss you can accept, and your data fits in memory. Many teams use it for data that is valuable but rebuildable (sessions, rate limits, leaderboards) and keep the system of record elsewhere.
Your turn
Your team caches rendered product pages (50 KB each, 200 GB total) and nothing else. A colleague insists on Redis Cluster with AOF persistence. What would you question?
Learn it from the source
- Redis — Data types ↗The data structures, with the commands each one supports.
- Redis — Persistence ↗RDB versus AOF, fsync policies, and what each can lose.
- Redis — Key eviction ↗Every maxmemory policy, including the noeviction default.
- Memcached wiki ↗The project's own documentation: protocol, configuration and design.
- Redis — Licenses ↗The licence terms for current Redis versions.
- Valkey ↗The BSD-licensed fork maintained under the Linux Foundation.
Related concepts
All concepts on one page: system design cheat sheet