Redis

Redis vs Memcached: Which Cache Fits Your Workload

Scott Sternloff

By Scott Sternloff, Senior Enterprise Architect

LinkedIn · Updated

Choose Memcached when you need a simple, multithreaded, volatile cache for pre-serialized values and are happy for the client to handle sharding. Choose Redis, or its BSD-licensed fork Valkey, when you need data structures, persistence, replication with automatic failover, or server-side sharding. Licensing is the other difference: Memcached is BSD licensed, Redis 8 is offered under RSALv2, SSPLv1 or AGPLv3, and Valkey is BSD.

Both keep data in memory and answer simple GET and SET requests quickly. The differences are in everything around that.

Redis vs Memcached at a glance

MemcachedRedis
Data modelKey plus an opaque value; the server does not understand data structuresStrings, hashes, lists, sets, sorted sets, streams, vector sets and more
Maximum value size1 MB per item by default512 MB per string value
PersistenceNone to disk; warm restart (1.5.18 and later) survives clean restarts; extstore can move values to flashRDB snapshots, an append-only file, or both
Replication and failoverNone; servers do not talk to each otherAsynchronous replicas, Sentinel, Redis Cluster
ShardingClient-side hashing across independent serversClient-side, or server-side with Redis Cluster's 16,384 hash slots
ThreadingMultithreaded, 4 worker threads by defaultCommands on one main thread; optional I/O threads
EvictionLRU within each slab class, plus expiryConfigurable maxmemory-policy, plus expiry
LicenseBSDBSD to 7.2; RSALv2 or SSPLv1 for 7.4; adds AGPLv3 from 8.0. Valkey: BSD

Data structures: the biggest practical difference

A Memcached item is a key, an expiry time, optional flags and raw bytes. The server stores whatever the client serialized and offers little beyond get, set, delete and simple increments. To change one field of a cached object, the client reads the whole value, deserializes it, edits it and writes it back, using check-and-set (CAS) if other writers might race it. Keys are limited to 250 characters.

Redis does that work on the server. You can increment one field of a hash, add a score to a sorted set or push onto a list in a single atomic command. That is why Redis gets used well beyond caching, for sessions, rate limits, leaderboards and queues; our guide to what Redis is used for covers each. If your application only stores rendered fragments or serialized query results, Memcached's simpler model costs you nothing.

Persistence and restarts

Memcached treats forgetting as a feature. A restart used to mean an empty cache; since version 1.5.18, warm restart can recover the cache across clean restarts such as binary upgrades, with caveats: changing the memory limit, maximum item size or slab sizes starts it clean, and the system clock must not jump while it is down. A crash still means a cold cache. Extstore extends a node's capacity by keeping keys in RAM and values on flash, but it is a capacity feature, not durability.

Redis can persist with RDB snapshots, an append-only file or both, and reload the data on restart. It can also run with persistence off when it is used purely as a cache. The trade-offs, including how much each option can lose, are covered in our section on Redis persistence.

The practical test is what happens to your database when the cache empties. A cold cache sends every miss to the source of truth at once. If the database cannot absorb that, you need either a cache that survives restarts or a plan to warm it.

Replication, high availability and scaling out

Memcached servers are unaware of each other. There is no crosstalk, synchronization or replication; the client picks a server for each key by hashing. Adding servers adds memory. Losing a server loses its share of the cache, and those keys miss until the application refills them. The Memcached documentation argues that replication would halve the usable cache and that an application should tolerate a few percent of extra misses.

Redis has replicas built in. Sentinel promotes a replica automatically when a primary fails, and Redis Cluster adds server-side sharding across several primaries. Replication is asynchronous, so a failover can drop the last writes, but the dataset survives the loss of a node. Choose Redis if a node failure must not empty part of the cache.

Threading and performance

Memcached is multithreaded and starts four worker threads by default, so one process can use several cores. Redis executes commands on a single main thread. Redis 8 introduced a new I/O threading implementation, enabled with io-threads, that moves socket reads, request parsing and reply writes onto extra threads, and Valkey 8.0 reworked its I/O threading in the same direction. To use many cores for command execution, Redis's documentation still recommends running more instances or sharding.

Redis's benchmarking guide notes that Redis and Memcached in single-threaded mode can be compared fairly on GET and SET, and warns against comparing numbers from different benchmark tools. For most applications the network, the client library and the value size matter more than the server. Test with your own payloads before choosing on speed.

Memory efficiency

Memcached manages memory with a slab allocator. Memory is split into 1 MB pages, each page is assigned to a slab class with a fixed chunk size, and every class keeps its own LRU. An item is stored in the smallest chunk that fits it, so some bytes are wasted per item, and a workload whose item sizes drift over time can leave memory sitting in classes that no longer need it while other classes evict.

Redis allocates per key through its memory allocator. Fragmentation, replication buffers and the copy-on-write cost of the snapshot fork can push resident memory well above the dataset size; our Redis memory guide explains how to size for it. Neither is universally more compact. Load a representative sample of your data into each and measure.

When to choose which

Memcached fits when:

  • you cache serialized objects, query results or page fragments under 1 MB
  • losing part of the cache on a node failure is acceptable
  • you want to scale a few large nodes vertically across many cores
  • you want the smallest operational surface

Redis or Valkey fits when:

  • you need data structures and atomic server-side operations
  • the cache must survive restarts, or node failures must not lose data
  • the same store also handles sessions, rate limiting, queues or leaderboards
  • you want server-side sharding with automatic failover

If the Redis license is the concern, Valkey keeps the Redis feature set under BSD; our Valkey vs Redis comparison covers the differences.

When to get help

Moving between the two is a cache migration, not a data migration: the new cache starts cold and fills from the source of truth, so the real work is sizing, client configuration and protecting the database while hit rates recover. AceMQ supports both sides: Memcached support for slab tuning, eviction and capacity, and Redis support and Valkey support for the persistence, replication and cluster questions that come with Redis.

Sources

Frequently Asked Questions

Is Redis faster than Memcached?

Neither is faster in general. For simple GET and SET on small values both answer from memory and perform similarly. Memcached spreads work across worker threads in one process, while Redis executes commands on one main thread with optional I/O threads. Benchmark with your own payloads and client settings.

Does Memcached support persistence?

Not in the way Redis does. Memcached does not write the cache to disk for crash recovery. Since version 1.5.18 its warm restart feature can keep the cache across clean restarts, and extstore can move item values to flash storage, but after a crash the cache starts empty.

Does Memcached support replication?

No. Memcached servers are unaware of each other: no replication or synchronization between them. Clients hash keys across servers, so losing a server loses its share of the cache until those keys are repopulated.

What is the maximum value size in Redis and Memcached?

Memcached limits items to 1 MB by default. A Redis string value can be up to 512 MB, although values that large are rarely a good idea in practice.

Is Memcached open source?

Yes. Memcached is released under a BSD license. Redis 8 is available under RSALv2, SSPLv1 or AGPLv3, and Valkey, the Linux Foundation fork of Redis, is BSD licensed.

Is Valkey an alternative to Memcached?

Yes, when you want Redis features under a BSD license. Valkey keeps the Redis data structures, persistence, replication and cluster mode, so it covers the cases where Memcached is too simple without the Redis 8 license terms.

Can I use Redis and Memcached together?

Yes. Some estates keep Memcached for a large cache of serialized objects and use Redis or Valkey for sessions, counters, queues and other features that need data structures or persistence.

Free Consultation

Get Expert Eyes on Your Redis Deployment

Whether you're troubleshooting a production incident, planning a migration, or want a second opinion on your architecture — our team is ready. No pitch, just answers.

Email Us