Comparison of Redis and memcached _memcached

Source: Internet
Author: User
Tags memcached memory usage redis redis cluster
Memcached is a high-performance distributed memory object caching system for dynamic Web applications to reduce database load. It reduces the number of database visits by caching database query results in memory to improve the speed and scalability of dynamic Web applications.
Redis is a key-value storage system and is a high-performance key-value database.
Caching mechanisms are often an important starting point for solving problems when considering performance improvements to applications, while memcached and Redis are often compared as preliminary scenarios.
Two similarities:
Memcached and Redis are both in-memory, key-value data storage scenarios. From a performance perspective, the two types of data storage mechanisms also have many commonalities, including the performance of almost identical features (and metrics), and a high degree of attention to workload data throughput and latency.
Memcached and Redis have a client library that can provide support in any of the feasible programming languages, and both are included in a variety of libraries and packages used by developers.
Different points:
1. Data persistence supports different
Memcahced does not support data persistence and data loss after server shutdown. Redis supports data persistence and data synchronization.
Restarting the memcached and restarting the operating system can cause all data to disappear. In addition, the unused cache is automatically deleted based on the LRU (least recently Used) algorithm after the content capacity reaches the specified value. The memcached itself is a server designed for caching, so there is no undue concern about data permanence.

2. Data types support different
Memcached only supports simple key-value structure data. The data types supported by Redis are much richer. The most commonly used data types are five kinds: String, Hash, List, set, and sorted set. Redis internally uses a Redisobject object to represent all key and value.

      3. Memory management mechanism different           in Redis, not all data is stored in memory. This is one of the biggest differences compared with memcached. When physical memory is exhausted, Redis can swap out some of the value of a long time to disk. Redis only caches all key information, and if Redis finds that memory usage exceeds a certain threshold, the operation of swap will be triggered, Redis according to "swappability = Age*log (size_in_memory)" calculates which key corresponding value needs to be swap to disk. The value corresponding to these keys is then persisted to disk and purged in memory. This feature allows Redis to maintain data that exceeds the memory size of its machine itself. Redis is much simpler than the memcached memory management approach.
     4. Cluster Management different
          as a memory-based storage system, the size of the machine's physical memory is the maximum amount of data the system can hold. If the amount of data to be processed exceeds the physical memory size of a single machine, a distributed cluster needs to be built to extend the storage capacity.
         memcached does not support distributed itself, so distributed memcached can only be implemented on the client side through a distributed algorithm such as a consistent hash. The following figure shows the memcached distributed storage implementation architecture. Before the client sends data to the memcached cluster, it first calculates the target node of the data through the built-in distributed algorithm, and then the data is sent directly to the node for storage. However, when the client queries the data, it also calculates the node where the query data resides, and then sends a query request directly to the node to get the data.

Redis is more inclined to build distributed storage on the server side. The latest version of Redis has already supported distributed storage capabilities. Redis cluster is a Redis advanced version that implements a distributed, single point of failure that does not have a central node and has a linear, scalable function. The following figure gives the distributed storage architecture of Redis cluster, in which the nodes communicate with each other through binary protocol, and the node communicates with the client through the ASCII protocol. On the placement strategy of the data, Redis cluster divides the value field of the entire key into 4,096 hash slots, and one or more hash slots can be stored on each node, meaning that the maximum number of nodes supported by the current Redis cluster is 4096. The distributed algorithm used by Redis cluster is also simple: CRC16 (key)% Hash_slots_number.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.