Redis vs Memcache

memcacheredis

I'm a bit new to Memcache and Redis and I'm trying to understand the difference between the two and what each actually is.

As has been explained to me Memcache is a database caching solution. Data from frequently run queries are cached to be re-used at a later point speeding up response time. Is that an accurate description?

What about Redis? Does that work in a similar manner? In other words does it cache data it receives from a backend database? I keep reading that Redis is is a key value store solution which to me sounds like more of a replacement for a database server vs a db caching solution.

Any help understanding what each is and what the differences are would be greatly appreciated.

Thanks
Brad

Best Answer

There is really one key difference between the two.

  • Redis = Key/Value caching
  • Memcached = Object caching

Both can be manipulated into caching whatever you want to throw at them. The ultimate goal of either of these systems and many others like them is to provide a distributed in-memory cache to store whatever data you need access to in a faster way. This essentially relegates the database to a simple data repository for persisted and long term storage while the in-memory cache mechanism offloads and moves as much data as possible and feasible to the front-end of the stack thereby reducing the latency and time to retrieve the data.

As you point out, Redis is really intended for just Key and Value caching however I have seen whole objects stored before. It does lend itself well to database performance improvements however.

Memcached is a bit more flexible in that it can pretty much store whatever you want it to. It's also one of the top contendors for any distributed memory cache application. There are other systems that do this too as well.

Either way, software has to be written to load either of these two caches. Some existing software may exists for whatever purpose you have in mind such as loading a table into memory but those would be specific for each case.