Need advice about which tool to choose?Ask the StackShare community!
Memcached vs Redis: What are the differences?
Key differences between Memcached and Redis
Memcached and Redis are both popular in-memory data stores used for caching and improving the performance of applications. However, there are several key differences between the two.
Data Structure Support: Redis supports a wide variety of data structures such as strings, lists, sets, sorted sets, and hashes, whereas Memcached only supports a simple key-value store without any built-in support for complex data structures. This makes Redis more versatile and suitable for a wider range of use cases.
Persistence: Redis provides the option to persist data to disk, allowing the data to be recovered in case of a system restart or failure. Memcached, on the other hand, does not offer any built-in persistence mechanism and relies solely on system memory for data storage. This makes Redis more reliable in situations where data durability is required.
Data Expiration: Redis allows setting an expiration time for individual keys, providing a convenient way to automatically remove data after a certain period. Memcached, on the other hand, relies on the Least Recently Used (LRU) eviction strategy and does not support setting explicit expiration times for individual keys. This makes Redis more suitable for scenarios that require fine-grained control over data expiration.
Replication and Clustering: Redis supports replication and clustering, allowing data to be replicated across multiple nodes or distributed across a cluster of servers. This provides scalability, high availability, and fault tolerance. Memcached, on the other hand, does not provide built-in support for replication or clustering, making it less suitable for scenarios that require high scalability or fault tolerance.
Advanced functionalities: Redis offers advanced functionalities such as pub/sub messaging, transactions, Lua scripting, and support for complex data manipulations. These features enable Redis to be used as a versatile data store and a message broker. Memcached, on the other hand, focuses primarily on caching and does not provide these advanced functionalities.
Memory Efficiency: Memcached is generally more memory-efficient compared to Redis for storing large volumes of data. Redis stores more metadata per entry, leading to higher memory usage. However, Redis provides efficient memory management techniques such as memory compression and virtual memory that can help mitigate this issue in certain scenarios.
In summary, Redis offers a more diverse set of features and capabilities compared to Memcached, including support for complex data structures, persistence, data expiration, replication, clustering, advanced functionalities, and memory efficiency. Memcached, on the other hand, excels at being a lightweight and performant caching solution.
The obvious volatile memory choices were either Memcached or Redis. We eventually sided with Redis as it natively handled replication, and this replication fell under the PCI responsibility scope of AWS. This added duribility meant that if a redis node were to die, our downtime would be in the seconds, rather than 15 minutes which we would incur using Memcached
The requirement was the classic "cache the results of a SQL query for a period of time."
While the Internet is full of "Redis is fuller featured" posts, the key issue for us was the actual performance. We discovered, in various stress scenario testing, that Memcached outperformed Redis for simple key-value retrieval dramatically (over twice as fast.) That's not to say that Redis is bad - we use that in other places where the requirements are more sophisticated than simple key/value retrieval.
Pros of Memcached
- Fast object cache139
- High-performance129
- Stable91
- Mature65
- Distributed caching system33
- Improved response time and throughput11
- Great for caching HTML3
- Putta2
Pros of Redis
- Performance886
- Super fast542
- Ease of use513
- In-memory cache444
- Advanced key-value cache324
- Open source194
- Easy to deploy182
- Stable164
- Free155
- Fast121
- High-Performance42
- High Availability40
- Data Structures35
- Very Scalable32
- Replication24
- Great community22
- Pub/Sub22
- "NoSQL" key-value data store19
- Hashes16
- Sets13
- Sorted Sets11
- NoSQL10
- Lists10
- Async replication9
- BSD licensed9
- Bitmaps8
- Integrates super easy with Sidekiq for Rails background8
- Keys with a limited time-to-live7
- Open Source7
- Lua scripting6
- Strings6
- Awesomeness for Free5
- Hyperloglogs5
- Transactions4
- Outstanding performance4
- Runs server side LUA4
- LRU eviction of keys4
- Feature Rich4
- Written in ANSI C4
- Networked4
- Data structure server3
- Performance & ease of use3
- Dont save data if no subscribers are found2
- Automatic failover2
- Easy to use2
- Temporarily kept on disk2
- Scalable2
- Existing Laravel Integration2
- Channels concept2
- Object [key/value] size each 500 MB2
- Simple2
Sign up to add or upvote prosMake informed product decisions
Cons of Memcached
- Only caches simple types2
Cons of Redis
- Cannot query objects directly15
- No secondary indexes for non-numeric data types3
- No WAL1