Memcached vs Redis

Posted on Saturday June 22, 2013 / by Eric Potvin

What is Memcached?

Free and open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.

What is Redis?

Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.


They seem similar but, in fact, they are different.

Memcached and Redis are both key/value storage system. Both of these system handle data directly in memory (RAM).

Storage type

Memcached stores variables in it's memory. Which mean, it retreive any information directly from the servers memory. Redis on the other than, is like a database that resides in memory. It executes (read and write) a key/value pair from its database to return the resultset. All data resides in memory.

Read/Write

Memcached is very good to handle high traffic websites. It can read lots of information at a time and give you back a great response time (lower the better). Redis can also handle high traffic on read but also can handle heavy writes as well.

Data Structure

Memcached uses string and integer as data structure. Everything you save can be either one or the other. With integer, the only data manipulation you can do is adding or subtracting them. If you need to save arrays or objects, you will have to serialize them first and then save them. To read them back, you will need to unserialize.

Redis has a stronger data structures. It can handle strings, integer as well but also can handle binary-safe strings, lists of binary-safe strings, sets of binary-safe strings and sorted sets.

Persistent

If you are using Memcached and you restarts the server or the server crash, none of the data you saved will be available. You will have to start all over.

Redis, on the other than, can handle persistent data. At any time if you want to save/store the data, you simply have to tell to the server to save it and that's it!

Installation/Configuration:

Both of these system are easy to install. The only difference is Redis provides a bit more configuration options if you need to optimize.

Simplicity

If you simply want to save a key/value pair or you don't really care about losing data in case of a server crash, Memcached if more memory efficient.

Key Length

Memcached key length has a maximum of 250 bytes whereas Redis key length has a maximum of 2 GiB.

Security

There is no security built into Memcached nor Redis. Both of these systems needs to be accessed by trusted clients inside trusted environments.

Replication

Memcached does not supports replication. Redis supports replication using a master and multiple slaves.