If you are finding a solution for server-side caching, it is likely that you have seen some suggestions like Redis or Memcached.
This article aims to differentiate Redis and Memcached and identify which one is best suited for a specific system.
Here are some benefits of Redis:
And here are its drawbacks:
Here are what Memcached offers:
However, there are also some drawbacks:
Redis supports most of the commonly used data types such as String, Hash, List, Set, Sorted, alongside bitmap and geospatial, and can store data up to 512MB in size.
Memcached, on the other hand, only supports String data type with only a maximum value of 1MB.
When using simple String data, Memcached has a better memory utilization rate than Redis. But when it comes to more complex data, as Redis supports Hash structure, it has a better memory utilization rate.
Redis has built-in commands like MULTI, EXEC, DISCARD, and WATCH to support transaction processing. In contrast, Memcached does not support transaction processing.
Both Redis and Memcached are pretty fast when reading, but Redis is a little bit faster.
Memcached is much faster than Redis after the records reach more than 100,000.
Redis supports data persistence through RDB snapshots and AOF logs, which help bootstrap caching data after a planned restart or an unintentional system failure.
Whereas, Memcached only stores data in memory and does not support data persistence.
Redis is mostly a single-threaded server, which is why it will not benefit from multiple cores CPU servers. However, its native support for clustering enables it to scale horizontally.
Memcached can easily scale vertically, as it is multithreaded. It can also be scaled horizontally, but not without the help of many popular Memcached clients. Plus, many major cloud service providers also help Memcached scale horizontally easily by providing data partitioning.
Redis supports publishing and subscribing to messages through the pub/sub message queues.
Memcached does not support publishing and subscribing to message
Use Memcached when:
Opt for Redis when:
In conclusion, Redis is a better choice for data structures, atomic operations, and transaction processing. Meanwhile, Memcached is an excellent choice for simple string data, multithreading support, and easy-to-use development. Additionally, Redis is suitable for systems that require data persistence, while Memcached is suitable for systems that do not.