The Short Answer
Both keep data in memory and answer requests over the network. Memcached stores values under keys and nothing else: it is a cache, and everything in it is lost when it restarts. Redis stores structured values, can write them to disk, and can replicate them to other servers. Which one fits depends on what the application needs and which one its libraries support.
At a Glance
| Feature | Redis | Memcached |
|---|---|---|
| Data | Many types | Plain values |
| Persistence | RDB, AOF | None |
| Replication | Built in | None |
| Threads | Mostly one | Many |
| Default port | 6379 | 11211 |
Data Types
Memcached values are opaque strings or byte blobs, with a size limit per item (1 MB by default). The application serializes its data and reads it back whole.
Redis has strings, hashes, lists, sets, sorted sets, streams, and more, and commands that work on them in place: add to a list, increment a counter, update one field of a hash, or read the top entries of a sorted set. That makes Redis useful for counters, leaderboards of any kind, rate limits, and queues, not only for caching. The everyday commands are in redis-cli commands.
Persistence
Memcached never writes data to disk. A restart or a reboot empties it, which is fine for a cache that can be rebuilt from the database.
Redis can save snapshots (RDB), log every write to an append-only file (AOF), use both, or neither. With persistence on, data survives a restart, which matters for sessions and queues.
Replication and Scaling
Redis supports replicas that copy a primary, Sentinel for automatic failover, and Redis Cluster for spreading keys over several nodes. Memcached servers know nothing about each other; the client library spreads keys across several servers by hashing, and when one server goes away its share of the cache is lost.
Threading
Memcached is multi-threaded and uses several CPU cores in one process. Redis executes commands on one main thread, which keeps every command atomic; recent releases can use extra threads for network I/O. To use more cores with Redis, run several instances or a cluster.
Memory and Eviction
- Memcached: a fixed memory limit set with
-m, divided into slabs by item size. When it is full, the least recently used items are evicted. - Redis: a limit set with
maxmemoryand a policy set withmaxmemory-policy. On a 64-bit server there is no limit until you set one. The default policy,noeviction, then refuses new writes when the limit is reached; a cache usually uses an LRU or LFU policy instead, such asallkeys-lru.
Typical Uses
- Page and query cache: both work well.
- PHP sessions: both have PHP session handlers; Redis keeps sessions across a restart when persistence is on.
- Queues and background jobs: Redis, through lists or streams.
- Shared counters and locks: Redis, through atomic commands.
Keep Both off the Internet
Neither should be reachable from the internet. Bind them to 127.0.0.1 or a private network address, and block their ports in the firewall: see how to set up the ufw firewall. Redis also has protected mode and password or ACL authentication. Memcached runs without authentication unless you turn it on: SASL for the binary protocol needs a build with SASL support, and since version 1.5.15 the -Y option enables a simple password file for the text protocol. Neither encrypts traffic, so a private address and firewall rules remain the main protection. On Debian and Ubuntu the packaged Memcached listens only on localhost by default.
Valkey
When Redis changed its license in 2024, Valkey was started as a community fork under the Linux Foundation. It speaks the same protocol and works with Redis clients, and some distributions package it alongside or instead of Redis. To set up Redis itself, see how to install Redis; for the wider picture of data stores, see SQL vs NoSQL.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations