Memcached vs REDIS

Memcached vs Redis: Which One is the Best for You?

When it comes to server-side caching solutions, there are no bigger names than Memcached and Redis. These caching solutions dominate the industry and are used by some of the biggest websites out there.

Each of them has distinct advantages and disadvantages, which means picking one comes down to the needs of your website. Of course, this is true for just about everything when it comes to web design.

It’s all about what works best for your specific situation.

That said, if you run a typical website, they will have similar results to one another. The real differences show up on larger websites that deal with far more data than a typical blogging site.

Let’s take a look at what these solutions are and how they compare to figure out which one is the best for you.

Memcached vs. Redis: Overview

Before we start looking at the finer parts of each caching solution, let’s just do a quick overview of each. For greater detail, refer to the other sections listed below.

What Is Memcached?

Memcached is a free open-source caching solution that was invented in 2003. It stores data using strings, and the amount of data it can store is only limited by the hardware it is stored on.

Thus, it can be scaled easily by adding more hardware.

If it runs out of room to store the data, it will begin overwriting the oldest data that has not been used in some time. This can somewhat be problematic for some industries, thus, the proper procedures need to be taken to ensure important info is not lost.

What Is Redis?

Redis, or Remote Dictionary Server, is an open-source caching solution that prioritizes performance more than other solutions. It was invented in 2009.

It stores data using several types of data (string, hash, list, set, and sorted set) which allow it to quickly access the data stored. You can even edit said data without having to load it, which results in a faster solution.

If a memory limit is reached, then Redis will return an error instead of deleting old data. Overall, users get to enjoy a fast caching experience on their website.

Memcached vs. Redis: Data Storage

While Memcached and Redis both do an excellent job at storing data, they go about it quite differently. This gives each one an advantage in certain situations over the other.

Let’s take a look at how each one works.

Memcached: Data Storage

Memcached stores all of the data as string keys and keys up to 250B and values up to 1MB. The data stored takes up very little room when compared to other server-side caching solutions, which makes it attractive to larger websites.

It takes advantage of a “Slab.” This segments the memory into multiple chunks of varying sizes. The keys are then stored in the chunk that corresponds to their size, which prevents memory fragmentation from occurring.

In terms of storage capacity, you are limited by the amount of memory available on your hardware. This can be expanded upon as needed, which makes it very scalable for larger websites.

Memcached is used by some of the largest websites in the world like YouTube.

Redis: Data Storage

Redis stores data using five unique data types that include:

  • String
  • Hash
  • List
  • Set
  • Sorted Set

The data types provide a unique advantage over other caching solutions that give you access to each field within one. This allows the system to carry out any CRUD (Create, Read, Update, Delete) function as needed.

Redis supports keys up to values of 512MB. It also supports data type operations, which allow you to edit any data stored within without having to load it.

This saves time as you not only avoid loading the data but also avoid having to store the data again.

Redis utilizes a Master/Slave architecture, which helps add redundancy to the system. If a Master fails, then a Slave is promoted to take its place.

This makes Redis harder to maintain on larger sites due to the complexity of the architecture but is more secure.

Memcached vs. Redis: Setup

Many users are building a website for the first time, which means they are looking for the easiest caching solution to manage.

Let’s take a quick look at what each one entails.

Memcached: Setup

One of the main reasons Memcached has been a dominant force in the industry is due to its simplicity. It is really easy to get started with Memcached on any Windows or Unix device. It can also adapt to any language such as PHP, C, etc.

Due to how dominant it has been over the years, there are a variety of resources you can take advantage of to help you along.

In many cases, your web host will set this up for you upon request. And in some cases, some platforms will have additional tools to make it easier to set up and manage.

Redis: Setup

Redis is a bit trickier to set up, but it is not difficult for your standard sites. More and more web hosts support Redis and will help you install it on your web server upon request. That said, they do not help you manage it.

Resources are becoming more readily available, but there are fewer overall.

That said, tools are coming out that can help make the setup easier. For instance, in WordPress, the Redis Object Cache plugin can help you set up Redis in just a few minutes.

On more complicated networks, it is worth pointing out that Redis has far more flexibility in terms of setup. This can make it more complicated, especially if you need to run multiple nodes simultaneously.

Memcached vs. Redis: Persistence

Some websites will need persistence from their caching solution. This means when the web server is restarted for whatever reason, that the data stored is not lost. Only one of these solutions supports the function.

Memcached: Persistence

Memcached does not support persistence operations. When the server is restarted, the data is lost.

Redis: Persistence

Is Redis persistent?

Yes, Redis provides several options when it comes to persistence. These include :

  • RDB (Redis Database)
  • AOF (Append Only File)
  • No persistence
  • RDB + AOF

The official Redis documentation goes into great detail about the robust options you have available. To keep it simple, you can quickly restore data from any point. This allows you to get your website operating in seconds.

Memcached vs. Redis: WordPress Sites

Odds are your website was built using WordPress, which both of these caching solutions work on. However, these solutions are not quite equal anymore and one is beginning to outshine the other.

Though, results vary based on what kind of website you’re building.

Memcached: WordPress Sites

For a long time, Memcached was the go-to caching solution for WordPress. It offers users an incredibly easy setup and a great performance out of the box.

As such, there are a variety of caching plugins you can utilize Memcached with like W3 Total Cache.

Memcached excels as a caching solution when websites constantly deliver the same page to visitors. This is especially true for one-page business sites due to a fast response time. This drastically lowers page load times.

In many cases, it is still the default caching solution for many web hosts.

Redis: WordPress Sites

Redis has been gaining ground over the last few years and has really become the best caching solution for most WordPress sites.

It stores the data in memory using the server’s RAM. While the amount of data it can store is low, it is much faster than other solutions.

For the most part, the average WordPress blog will not come anywhere close to exceeding what your web server’s RAM can handle. This results in it being the fastest solution available, but it is not quite as easy to set up as other solutions.

The good news is that due to its explosive popularity, most web hosts have begun to support Redis and can help with the installation process.

If your website is focusing more on speed, Redis is by far the best option for a standard WordPress site.

Memcached vs. Redis: Which is Better?

While it largely depends on what kind of site you are running, on a general level, Redis will end up being the better option, especially in the WordPress ecosystem.

When set up correctly, it delivers the fastest caching experience and has more features to take advantage of.

This gives it far more flexibility with dealing with bigger sets of data. Of course, this flexibility does come at the price of complexity. Redis will be slightly harder to maintain and manage when compared to Memcached, but the performance boost is worth the effort.

That said, either solution will work for the majority of websites out there. It just depends on the data you are working with and your ability to properly configure each to fit the situation.

Which caching solution did you choose? Did you notice a performance boost when switching from one solution to another?