![Memcached Vs Redis, Why to pick them for web application? Memcached Vs Redis, Why to pick them for web application?](http://learnitworld.com/wp-content/uploads/2015/09/mem_redis.png)
Memcached Vs Redis, Why to pick them for web application?
Memcached is quite different from Redis.
Memcached stores data in memory and loses all stored data (cache) when the server is restarted.
Redis instead can be persistent and can keep stored data even when the server is restarted, more over Redis has more features ( like List, Set, Hash, etc.).
We use Memcache for lot of things and it does it good, and in future if we need persistence, we can always switch for memcachedb which uses memcache protocol but has a berkelydb backend.
The Big question which comes in mind, that which to use Redis or Memcached? This wholly depends on what type of application you are going to use them. let us discuss all Redis and Memcached Similarities then their difference, based on the below discussion we can decide which is more preferable for our host web application. Let’s start with Similarities.
Similarities
Both Memcache and Redis are in-memory, key-value data stores, And both belong to the NoSQL family of data management solutions. They both keep data in live RAM, which of course makes them rightly available. In terms of performance, both have almost identical characteristics with respect to throughput and latency.
Besides being in-memory, key-value data stores, both Memcached and Redis are mature and hugely popular in open source projects. Memcached was originally developed by Brad Fitzpatrick in 2003 for his LiveJournal website. Originally it was written in Perl, then rewritten in C by Anatoly Vorobey.
Currently, the development of Memcached is focused on stability and optimization.
Redis was created by Salvatore Sanfilippo in 2009. Redis is sometimes described as
“Memcached on steroids” which is hardly surprising considering that parts of Redis were
built in to improve fault which was learned from using Memcached. Redis has more features than Memcached, which makes it more powerful and flexible but also more complex.
Why are Memcached and Redis so popular? Not only are they extremely effective. They’re also relatively simple. Getting started with either Memcached or Redis is considered easy work for developers. it takes only a few minutes to set up and get it ready to work with any application. And the investment of small investment of time and effort can have an immediate, impact on performance.
Why use Memcached
Memcache is more useful for caching small and static data, such as HTML code fragments or SQL queries. Memcached internal memory management is not so mature as Redis, but much more efficient as Memcached consume less resource for metadata. Memcached supports a single data type i.e String which makes it more ideal for storing data that is directly read out without processing it.
Memcached has some advantages over Redis is horizontal scaling as part of the design and in part to its simpler capabilities, Memcached is much easier to scale.
Moreover, Memcached is very good to handle high-traffic websites. As it keeps all data in Memory and rightly available, So, it can read a lot of data and return it to you in great response time.
Why use Redis
Redis caches have a mechanism called data eviction to delete old data from memory to create space for new data in memory. Memcached data use a mechanism called LRU ( Least Recently Used) algorithm and which somewhat finds data of similar size and replaces it with new data. Redis also employs more sophisticated approaches to memory management and eviction candidate selection.
Redis gives you more flexibility regarding the objects you can cache. But
Memcached limits key names to 250 bytes, limits values to 1MB, and works only with plain
strings, Redis allows key names and values to be as large as 512MB each. Redis has six data types that enable more intelligent caching and manipulation
of cached data.
Redis does not stores objects as serialized strings, Redis stores object field and value in Hash and manage them using a single key. Redis saves us from the need to fetch the entire sting, de-serialize it, update a value, re-serialize the object, and replace the entire string in the cache with its new value for each necessary update, which means lower resource consumption and increased performance. And Redis’s other data types provide more complex data cache implementation and management patterns.
Redis offers optional and tunable data persistence, which is designed to bootstrap cache after a planned shutdown or an unplanned failure.
Redis also offers replication. Replication can be used for implementing a highly available cache setup that can withstand failure and provides uninterrupted service to the application.
Redis and Memcached are providing production ready solution by boosting up application performance through caching. Since Redis is rich in functionality and more advance design, Redis should be the first choice in most of the scenarios, but for application where we need simple data storage in the form of string without any complex manupulation