Points to consider
- Read / write speed
- Both are extremely fast. Benchmarks vary by workload, versions, and many other factors but generally show redis to be as fast or almost as fast as memcached.
- Memory usage
- Memcached
- No way to reclaim specified cache size, short of restarting memcached. All your keys could be expired, you could flush the database, and it would still use the full chunk of RAM you configured it with.
- Redis
- Setting max size is up to you. Redis will never use more than it has to and will give you back memory it is no longer using.
- Disk I/O dumping
- Redis
- Does this by default and has very configurable persistence
- Memcached
- No mechanisms for dumping to disk without 3rd party tools
- Scaling
- Both give tons of headroom before you need more than a single instance as a cache. Redis provides tools to help you go beyond that while memcached does not
Memcached
Memcached is a simple volatile cache server. It allows you to store key / value pairs where the value is limited to being a string up to 1MB and key is maximum size 250B.
You can access those values by their key at extremely high speed, often saturating available network or even memory bandwidth.
When you restart memcached your data is gone, which is fine for a cache.
If you need high performance or high availability there are 3rd party tools, products, and services available.
Redis
Redis is more than a cache. It is an in-memory data structure server.
Redis can store key / value pairs too and can be up to 512MB for both keys and values.
Stores 5 data types:
- String
- Hash
- List
- Set
- Sorted Set
You can turn off persistence and it will lose your data on restart, if you want your cache to survive restarts it lets you persist which is the default.
Redis includes cluster support and comes with high availability tools (redis-sentinel) right “in the box”.