Big Liar Redis/memcache Cache

Source: Internet
Author: User
Tags cas


First, memcache characteristics
1.
Memecache all of the data in memory, will be suspended after the power outage, the data can not exceed the memory size
Redis is partially present on the hard drive, which guarantees the data's durability.
2.
Memcache uses the memory allocation mechanism of the slab allocator: divides allocated memory into blocks of a specific length in a predetermined size to completely resolve memory fragmentation issues.
3.
Memcache exists in memory, the allocated memory is full, some k/v data will be deleted according to certain rules, all of which are lost naturally after reboot.
4.
Expiration policy--memcache is specified when set, such as set Key1 0 0 8, which never expires. Redis can be set through, for example, expire.
5.
The first thing to note is that Memcached supports the largest storage object of 1M. Its memory allocation is very special, but the allocation method is based on performance considerations, simple allocation mechanism can be more easily recycled redistribution, save the use of the CPU. Larger than 1M requires splitting.
6.
The maximum length of a key that memcached can accept is, 255 characters.
7.
The same data sends both a SET command and a GET command, which do not affect the other, but after get, the processing may be preceded by other set, the subsequent set will overwrite the previous, but Memcached 1.2.5 and later, provides the gets and CAS command, They can solve the problem above. If you use the GET command to query the item,memcached of a key, you will be returned with a unique identifier for the item's current value. If you overwrite this item and want to write it back to memcached, you can send the unique identity to memcached with the CAS command. If the item's unique identity in the memcached is consistent with what you provide, your write operation will succeed. If the item is also modified by another process during this time, the unique identity of the item stored in the memcached will change and your write will fail.
8.
No authentication, and the authentication is considered a higher level issue.
9.
Deleting the delete operation simply resets the chunk to a delete state, so that the next use will take precedence over such chunk.
10.
The flush operation is equivalent to an action that invalidates all the item. Does not change the memcache memory allocation situation.
11.
Memcache already allocated memory will no longer be actively cleaned up.
12.
Memcache the memory page assigned to a slab can no longer be assigned to another slab.
13.
Flush_all cannot reset the landscape of memcache allocated memory pages, just to expire all of the item.
14.
The memcache maximum stored item (key+value) size is limited to 1M, which is limited by the page size 1M.
15. Because the memcache distributed is the client program through the hash algorithm to get the key to take the model, different languages may use different hash algorithms, the same client program may also use dissimilar methods
, so in the multi-language, multi-module sharing the same set of memcached services, we must pay attention to the client to choose the same hash algorithm.
16.
When starting memcached, LRU substitution can be disabled through the-m parameter, and add and set will return failure when memory is exhausted.
17.
Memcached starts by specifying the amount of data storage, does not include the memory that it occupies, and the administrative space that is set up to save the data. As a result, it consumes more memory than the memory allocation specified at startup, which requires attention.


Second, Redis features
1.
Redis not only supports simple k/v types of data, but also provides storage of data structures such as List,set,hash.
(five types of data structures: string--strings, hash--dictionaries, list--lists, set--collections, Sorted set--ordered collections)
2.
Redis supports backup of data, that is, Master-slave mode of data backup.
3.
Redis supports data persistence, which keeps the in-memory data on disk and can be loaded again for use when restarting.
4.
Redis, with a certain database characteristics.
5.
Redis data can be stored on a hard disk with no expiration policy.
6.
Redis has a fatal flaw when the memory is full, the dump data CPU consumes 100%.

7.

Speed, Redis is faster than memcached, which is based on some benchmarks test results, and in memory usage, Redis breaks the physical memory limit and can use virtual memory;

8.

More data types than memcached, Redis supports list, Set, SortedSet, HashMap and many other data structures;

9. Persistence, memcached does not have a corresponding persistence mechanism, and Redis has an RDB snapshot and aof log two forms of the combination of persistence, to a large extent to ensure data persistence and security, not like memcached after the power outage.


three, memcache and Redis difference summary
Summary One:
1. Data type
Redis data types are rich, support set Liset and other types
Memcache support simple data types, requiring clients to handle complex objects themselves
2. Persistence
Redis Support data Landing persistent storage
Memcache does not support data persistent storage
3. Distributed Storage
Redis supports master-slave replication mode
Memcache can be distributed using a consistent hash
4.value size different
Memcache is a memory cache with a key that is less than 250 characters in length, a single item store smaller than 1M, and not suitable for use with
5 for a virtual machine. Data consistency differs
Redis uses a single-threaded model to ensure that data is submitted sequentially. The
Memcache needs to use CAS to ensure data consistency. CAS (Check and Set) is a mechanism for ensuring concurrency consistency and belongs to the "optimistic lock" category; The principle is simple: take the version number, operation, compare version number, if the operation is consistent, the inconsistency will abandon any operation
CPU utilization
Redis single-threaded model can use only one CPU , you can open multiple Redis processes


Summary Two:
1.Redis, not all of the data has been stored in memory, which is the biggest difference compared with memcached. The
Redis and Memcache both store data in memory and are in-memory databases. But memcache can also be used to cache other things, examples, videos, and so on.
2.Redis not only supports simple k/v-type data, but also provides storage for data structures such as List,set,hash.
3.Redis supports backup of data, that is, data backup of Master-slave mode. The
4.Redis supports the persistence of data, which keeps the in-memory data on disk and can be loaded again when it is restarted.
I personally think that the most essential difference is that Redis has a database feature in many ways, or a database system, and memcached is just a simple k/v cache
5.Redis has a database feature in many ways, or a database system, And memcached is just a simple k/v cache.
6. Their expansion requires clustering; implementation: Master-slave, Hash.
7. In more than 100k of data, memcached performance is higher than Redis.
8. If you want to say memory usage efficiency, using simple key-value storage, memcached memory utilization is higher, and if Redis uses hash structure to do key-value storage, because of its combined compression, Its memory utilization is higher than memcached. Of course, this is related to your application scenario and data characteristics.
9. If you have requirements for data persistence and data synchronization, it is recommended that you choose Redis because neither of these features memcached. Choosing Redis is also wise, even if you just want the cached data to be not lost after upgrading or rebooting the system. The
10.Redis and memcache have little difference in write performance, and read performance above especially bulk read performance above Memcache stronger.

Summary three:
The difference between Redis and Memecache is that:
1. Storage mode:
Memecache all of the data in memory, will be suspended after the power outage, the data can not exceed the memory size
Redis is partially present on the hard drive, which guarantees the data's durability.
2. Data support type:
Redis has much more data support than Memecache.
3, using the underlying model is different:
The new version of Redis directly builds its own VM mechanism, because a system function called by a general system can waste a certain amount of time moving and requesting.
4, the operating environment is different:
Redis currently only supports Linux, eliminating the support for other systems, which can be used to better optimize the environment of the system, although Microsoft has a team to write a patch for it. But not on the trunk.
Memcache can only be cached, cache
Redis content can be landed, which is similar to MongoDB, then Redis can also be used as a cache, and can be set Master-slave

Big Liar Redis/memcache Cache

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.