Both Redis and Memcache are memory-based data storage systems. Memcached is a high-performance distributed memory caching service, which is essentially a memory Key-value database. Redis is an open-source key-value storage System. Similar to memcached, Redis stores most of the data in memory and supports data types such as strings, hash tables, linked lists, collections, ordered collections, and related operations based on these data types. So, what's the difference between Memcache and Redis? Let's have a look.
1. Different data operation
Unlike data records that memcached only support simple key-value structures, Redis supports a much richer data type. Memcached basically only supports simple key-value storage, does not support enumeration, and does not support persistence and replication functions. Redis supports server-side data operations with more data structures and support for richer data operations than memcached, supports list, set, sorted set, hash and many other data structures, while providing persistence and replication capabilities. Usually in memcached, the user needs to take the data to the client to make similar modifications and set back, which greatly increases the number of network IO and the volume of data. In Redis, these complex operations are often as efficient as the general get/set. Therefore, Redis is a better choice if you need caching to support more complex structures and operations.
2. Different memory management mechanism
In Redis, not all data is stored in memory all the time. This is one of the biggest differences compared to memcached. When physical memory is exhausted, Redis can swap some long-unused value to disk. Redis will only cache all key information, and if Redis finds that memory usage exceeds a certain threshold, it will trigger swap operations, Redis according to "swappability = Age*log (size_in_memory)" Calculates which key corresponds to the value that requires 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 is larger than the memory size of its machine itself.
While memcached uses the slab allocation mechanism to manage memory by default, the main idea is to divide the allocated memory into blocks of specific lengths to store the corresponding length of key-value data records in a predetermined size to completely resolve the memory fragmentation problem.
In terms of memory utilization, memcached memory utilization is higher with simple key-value storage. If Redis uses a hash structure to do key-value storage, its memory utilization will be higher than memcached due to its combined compression.
3. Different performance
Because Redis uses only single cores, and memcached can use multicore, Redis on average has a higher performance than memcached for storing small data on each core. In more than 100k of data, memcached performance is higher than Redis, although Redis also in the storage of Big data performance optimization, but compared to memcached, or slightly inferior.
4. Different Cluster management
Memcached is a full-memory data buffering system, although Redis supports data persistence, but full memory is the essence of its high performance. 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 that needs to be processed exceeds the physical memory size of a single machine, it is necessary to build a distributed cluster to extend the storage capacity.
Memcached itself does not support distribution, so it is possible to implement memcached distributed storage only at the client through a distributed algorithm such as a consistent hash. Redis is more inclined to build distributed storage on the server side than memcached can only implement distributed storage with clients.
Summary: Which is better for Redis and memcached?
Redis more scenarios are used as substitutes for memcached, and Redis is more appropriate when more data type support or stored data than Key-value is required to be excluded. If only cache, memcached is enough to deal with most of the demand, the advent of Redis just provides a better choice. In general, according to the user's own needs to choose is the most appropriate.
At present, Huawei Cloud has the latest activities, database year in the huge benefits! Friends who need to practice in person can understand ~
Https://activity.huaweicloud.com/dcs_midyear/index.html
What is the difference between memcache and Redis?