Skip to main content

Side by side

RedisvsMemcached

What is the difference between Redis and Memcached?

Updated 3 min read7 differences

In short

Both keep data in memory; Memcached is a plain, multithreaded cache, while Redis adds data structures, persistence, replication and messaging.

Redis

Remote Dictionary Server

Redis is an in-memory key-value store that reads and writes in well under a millisecond, which makes it a popular cache, session store and message broker.

Read the page on Redis

Memcached

Memcached is an open-source, in-memory key-value cache that keeps small pieces of data in RAM across servers to take load off databases and speed up apps.

Read the page on Memcached

Redis and Memcached compared

AspectRedisMemcached
Data modelStrings, lists, sets, sorted sets, hashes, streams and morePlain keys and values; values are opaque bytes
PersistenceOptional snapshots and an append-only log on diskNone: data is lost on restart
Replication and clusteringBuilt-in replicas, Sentinel failover and Redis ClusterNone in the server; clients spread keys across nodes
ThreadingCommands on one main thread; extra threads for network I/OMultithreaded: one process uses every core
Value sizeUp to 512 MB per valueUp to 1 MB per value by default
ExtrasPub/sub, streams, Lua scripting, transactionsLittle beyond expiry, LRU eviction and simple counters
Best forCaches plus sessions, counters, leaderboards, queues and messagingLarge, simple caches of serialized objects or page fragments

The difference, explained

Redis and Memcached are both in-memory key-value stores that answer in well under a millisecond, and both are most often used as a cache in front of a slower database. Memcached, written in 2003, is a pure cache: it stores opaque values under keys and does almost nothing else. Redis, created in 2009, is a data structure server: its values can be strings, lists, sets, sorted sets, hashes and streams, and it can work as a primary data store, not only as a cache.

The difference comes from scope. Memcached keeps its feature set tiny on purpose: values are plain bytes, items expire or are evicted when memory fills, and the data is gone after a restart. Its servers never talk to each other; the client hashes each key to pick one. Redis adds persistence to disk, replication, built-in clustering, pub/sub, Lua scripting and atomic operations on its data types, such as INCR on a counter or ZADD on a leaderboard, so work that would need a read-modify-write round trip with Memcached happens inside the server.

Their execution models differ too. Memcached is multithreaded and uses every CPU core in one process, which makes it very efficient for large, simple caches. Redis runs commands on one main thread, which keeps every command atomic, and scales out by running several instances or a cluster; newer versions use extra threads for network I/O. In practice both are so fast that the network is usually the bottleneck.

A common misconception is that Redis has made Memcached obsolete. For a large, disposable cache of serialized objects or HTML fragments, Memcached is still simpler to run and very memory-efficient, and many large sites still use it. The opposite mistake is treating Redis as only a cache: once you rely on its data types, persistence or pub/sub, Memcached is no longer a drop-in replacement. Since Redis changed its license in 2024, the Linux Foundation's open-source fork Valkey has offered the same commands.

Which one should you use?

Choose Redis when…

  • You need more than strings: counters, sorted sets for leaderboards, hashes or streams.
  • Data should survive a restart or be replicated to another server.
  • You also want pub/sub messaging, queues or rate limiting from the same store.
  • Several operations must happen atomically on the server, through transactions or Lua scripts.

Choose Memcached when…

  • You only need a fast, disposable cache in front of a database.
  • Values are serialized objects or HTML fragments the app can rebuild on a miss.
  • You want one process to use many CPU cores with very little to configure.
  • Your stack already runs it and needs nothing more.

Caching a value, then adding to a score (Python)

Redispython
# Redis: a cache entry, plus a data structure kept on the server
import redis

r = redis.Redis(host="localhost", port=6379)
r.set("user:42:profile", profile_json, ex=300)  # expires in 5 minutes

# Leaderboard: the sorted set lives in Redis, updated atomically
r.zincrby("leaderboard", 10, "alice")
top3 = r.zrevrange("leaderboard", 0, 2, withscores=True)
Memcachedpython
# Memcached: values are opaque bytes with an expiry time
import json
from pymemcache.client.base import Client

mc = Client(("localhost", 11211))
mc.set("user:42:profile", profile_json, expire=300)

# Leaderboard: read the whole value, change it, write it back
board = json.loads(mc.get("leaderboard") or "{}")
board["alice"] = board.get("alice", 0) + 10
mc.set("leaderboard", json.dumps(board))  # not atomic

Readers ask

Is Redis faster than Memcached?

For simple gets and sets they are close, and the network round trip usually dominates. Memcached makes better use of many cores in one process, while Redis can do more work per request thanks to its data types.

Can Redis replace Memcached?

Usually yes: Redis can act as a pure cache with eviction and expiry times, and most client libraries make the switch easy. The cost is a somewhat more complex server with features you may not use.

Does Memcached save data to disk?

No, by default everything lives in memory and disappears on restart. Treat it as a cache whose contents can always be rebuilt from the real database.

More

Settings