Comparison of Caching Redis and Memcached

Original: http://bluenemo.iteye.com/blog/2157736


Memcached is a high-performance distributed in-memory object caching system for dynamic web applications to reduce database load. It reduces reads by caching data and objects in memory The number of times the database is fetched, thereby providing the speed of dynamic, database-driven websites.


Redis is a key-value storage system, similar to Memcached.


Data consistency problem
Memcached provides the cas command, which can ensure the consistency of the same data for multiple concurrent access operations.
Redis does not provide the cas command and cannot guarantee this. However, Redis provides the function of transaction, which can ensure the atomicity of a series of commands, and will not be interrupted by any operation in the middle.


In terms of memory management,
Memcached uses a pre-allocated memory pool, and uses slabs and chunks of different sizes to manage memory. Item selects the appropriate chunk storage according to the size. The memory pool method can save the overhead of applying/releasing memory, and can reduce Small memory fragments are generated, but this method also leads to a certain degree of space waste, and new data may also be eliminated when there is still a lot of space in memory.
Redis uses the method of on-site memory application to store data, and rarely uses free-list and other methods to optimize memory allocation, and there will be memory fragmentation to a certain extent. Redis will store data with expiration time separately according to the storage command parameters. Together, and call them temporary data, non-temporary data will never be culled, even if the physical memory is not enough, resulting in swap will not cull any non-temporary data (but will try to cull some temporary data), this point Redis is more suitable as a storage rather than a cache.


Storage methods and other aspects
Memcached basically only supports simple key-value storage, does not support enumeration, and does not support functions such as persistence and replication.
In addition to key/value, Redis also supports many data structures such as list, set, sorted set, and hash.


Regarding client support
in different languages, Memcached and Redis have rich third-party clients to choose from in terms of clients in different languages. However, because Memcached has been developed for a longer time, in terms of client support, Memcached Many clients are more mature and stable, and Redis is more complicated than Memcached because of its protocol itself, and the author keeps adding new functions, etc., the follow-up speed of the corresponding third-party clients may not be able to keep up, and sometimes it may be necessary to build on the basis of third-party clients. Make some changes to make it better.

When we don't want data to be kicked out, or need more data types than key/value, or when we need landing functionality, using Redis is more appropriate than using Memcached. Otherwise use Memcached.










Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327042372&siteId=291194637
Recommended