Memcached & Redis: Which should be used?

Tram Ho

Large systems always need a caching mechanism to increase processing speed as well as reduce network traffic to the database. Currently there are two very popular tools, Memcached and Redis , in this article I will compare the advantages and disadvantages of both and when to use which tool.

The same point

Redis and Memcached are both systems for storing data in memory. Memcached is a decentralized caching system with high speed, while Redis is a key-value memory. Like Memcached , Redis can store almost all types of data in memory and can perform calculations with many data types (e.g. string , hash table , linked list , …) .

Both of these tools are very fast and useful when used as caching, helping to speed up web applications by caching queries, HTML or anything that can be cached .

Differences in nature

As defined on the homepage of Redis :

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.

and the definition of Memcached :

Free & 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.

Two definitions we see, Redis is used as a database (used as the database) while Memcached is a storage system cache (memory caching system). To better understand this difference, we will compare on the following key aspects:

  • Server-end data operations ( operations on server-side data)
  • Memory usage efficiency (Level of efficiency in memory usage)
  • Performance comparison
  • Read / write speed
  • Disk I / O dumping (Backup data)

Server-end data operations

Redis supports server-side data operations, more data types and more operations than Memcached . So if you want your system to be able to cache but complex data structures, Redis would be a better choice.

Memory usage efficiency

Memcached works better with simple key-value data types. However, using Redis with hash constructs is more efficient than Memcached because it is designed to store such complex data types.

Performance comparison

Redis uses only one core while Memcached is optimized to use multiple cores . So Redis will have better performance than Memcached when comparing the amount of data on a core. However, Memcached outperformed Redis when comparing the overall amount of data. Although Redis has a mechanism to optimize for large data, it is still inferior to Memcached .

Read / write speed

Both are very fast. Although there are many influencing factors such as data volume, version, Redis is usually as fast as Memcached .

Disk I / O dumping

Redis has a default mechanism for backing up data to disk while Memcached does not have this mechanism without using the support tool.


Memcached is a simple cached server that allows you to store key-value pairs with data smaller than 1MB. It works extremely well but that’s all it can do. When you restart, the data will be lost, so Memcached is suitable for projects that only need to cache simple, light, and unimportant data. In addition, there are still tools, products, and services of third parties to add necessary features.

Redis can also do like Memcached , maybe even better. Redis can also be used as a cache but the data it can store up to 512MB. Unlike Memcached , Redis can still save its data after restarting, which is actually the default setting. In addition, Redis also has a cluster support mechanism that allows you to scale with multiple instances. The number of tools, services, ecosystems of Redis is also much larger, large systems use Redis also more than Memcached .

Reference source

Chia sẻ bài viết ngay

Nguồn bài viết : Viblo