All guides
Home Comparisons Redis vs Memcached
Comparison

Redis vs Memcached

Redis vs Memcached comparison: choosing between a feature-rich data structure store and a high-performance simple cache.

Side ARedis
VS
Side BMemcached
On this page

What it is

Redis and Memcached are in-memory data stores used to accelerate data access. Redis acts as a data structure store, while Memcached is a classic distributed object cache.

ParameterRedisMemcached
Data typesStrings, Lists, Hashes, Sets, Geo, BitmapsStrings only
PersistenceYes (RDB, AOF)No
ReplicationYes (Master-Slave)No (via third-party tools)
MultithreadingLimited (I/O threads since v6.0)Full support
TransactionsYesNo (Atomic CAS only)

Performance

Both systems provide sub-millisecond latency. Memcached utilizes multi-core processors more efficiently due to its multithreaded architecture, offering an advantage in raw throughput for simple key-value pairs under heavy load. Redis, being primarily single-threaded, may lag in raw string R/W throughput but outperforms Memcached when dealing with complex structures, as processing occurs server-side without transferring the entire object to the client.

Configuration & complexity

Memcached is extremely simple to configure: memory management is handled via Slab Allocation, which prevents fragmentation but limits object size (1 MB by default). Redis requires detailed redis.conf tuning, especially regarding disk snapshots and eviction policies. Redis offers 8 eviction strategies, including volatile-lru and allkeys-lfu, whereas Memcached uses LRU exclusively.

When to choose what

  • Choose Redis if: you need complex object caching, message queues (Pub/Sub, Stream), persistent session storage, or geospatial features.
  • Choose Memcached if: you need the simplest, most stable string cache, plan to scale horizontally across hundreds of nodes, and have no data persistence requirements.

Cost / licensing

Memcached is distributed under the BSD license. As of 2024, Redis transitioned to RSALv2 and SSPLv1 licenses, restricting its use for cloud service providers, though the source code remains available for most developers. Open-source forks like Valkey maintain the original permissive licensing.

Ecosystem & integrations

Redis features a rich ecosystem of modules (RedisJSON, RediSearch) and native support in all modern frameworks. Memcached is supported by conservative stacks (PHP, legacy Java apps) and cloud providers as a standard, no-frills caching service.

Verdict

For modern applications, Redis is the de facto standard due to its flexibility and feature set. Memcached remains relevant for specific high-load caching scenarios where multithreading and minimal metadata overhead are critical.

Performance and resources

Resource consumption differs significantly between the two engines due to how they allocate memory and schedule CPU threads. Memcached pre-allocates memory into fixed-size chunks grouped into slab classes. This prevents long-term memory fragmentation and guarantees predictable RAM footprints, though poorly sized items can cause slab calcification—where memory locked in one slab class cannot be reassigned to another without a restart or enabling slab_automove.

Redis allocates memory dynamically via jemalloc. It stores rich metadata alongside every key, which increases per-key memory overhead compared to Memcached's compact key-value headers. When storing millions of tiny strings, Memcached typically fits more keys into the same RAM budget. Furthermore, enabling Redis persistence (RDB snapshots or AOF rewrites) triggers a background fork() process. Under heavy write workloads, copy-on-write page duplication can temporarily double Redis's memory usage, requiring operators to leave substantial RAM headroom.

On the CPU side, Memcached scales linearly across available cores by assigning worker threads to incoming connections. Redis executes commands sequentially on a single main thread, utilizing extra cores only for network I/O (when io-threads is enabled) and background disk persistence. A single slow command in Redis, such as KEYS * or sorting a massive collection, blocks all other clients until completion.

When to choose Redis

  • Rate limiting and counters: Atomic operations like INCR combined with key expiration let you build sliding-window or fixed-window rate limiters without race conditions.
  • Leaderboards and real-time rankings: Sorted Sets maintain ordered scores natively, allowing instant range queries and rank lookups without pulling data into application memory.
  • Distributed locks and coordination: Conditional writes (SET key value NX PX) and Lua scripting support reliable locking mechanisms across microservices.
  • Durable session storage: Replication and disk persistence keep user sessions intact across node restarts or failovers, avoiding mass logouts during maintenance.
  • Lightweight message brokering: Redis Streams and Pub/Sub handle real-time event fan-out, task queues, and consumer groups without deploying a separate broker.

When to choose Memcached

  • High-throughput HTML fragment and query caching: Serving pre-rendered page blocks or serialized database rows under extreme read concurrency benefits directly from Memcached's multi-threaded network handling.
  • Ephemeral, stateless workloads: When cached data can always be reconstructed from a primary database and losing cache state on reboot is acceptable, Memcached avoids persistence overhead entirely.
  • Simple horizontal sharding: Client-side consistent hashing distributes keys across dozens of independent Memcached nodes without cluster bus gossip, slot migrations, or master-replica topology management.
  • Strict memory predictability: Workloads with uniform payload sizes under the 1 MB default limit run reliably without risking copy-on-write memory spikes.

Migrating between them

Moving from Memcached to Redis usually stems from outgrowing simple key-value caching. Because Redis supports standard strings with TTLs, basic GET and SET calls translate cleanly. However, pay attention to key eviction behavior: set maxmemory-policy allkeys-lru in redis.conf to mirror Memcached's automatic eviction of old keys when RAM fills up, rather than Redis's default noeviction setting which returns write errors.

Migrating from Redis to Memcached is less common and requires stripping out data-structure logic. Any application code relying on hashes, lists, or sets must serialize entire objects (using JSON, MessagePack, or Protobuf) in the client before storing them as plain strings. You must also replace server-side clustering with a client library capable of consistent hashing, such as Ketama, to route keys across nodes.

FAQ

Can I run Redis and Memcached on the same server?

Yes, provided you strictly bound their memory limits. Configure maxmemory in Redis and the -m flag in Memcached so their combined allocation stays well below physical RAM, leaving room for the operating system and Redis background forks.

Which system handles large objects better?

Redis supports string values up to 512 MB out of the box, making it much easier to store large payloads. Memcached caps items at 1 MB by default; while you can raise this via the -I flag, doing so reduces the number of available slab pages and lowers memory efficiency.

Do I need Redis Cluster if I only want caching?

No. For pure caching without cross-key operations, you can shard traffic across standalone Redis instances using client-side consistent hashing—just like Memcached—avoiding the operational overhead of cluster slot management.

Comparisons

More comparisons

All comparisons

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.