Comparison between memcahce and redis

Source: Internet
Author: User

I. memcache

1. memecache stores all the data in the memory. After the power is down, the data cannot exceed the memory size.
Some redis instances are stored on the hard disk to ensure data persistence.

2. memcache uses the memory allocation mechanism of Slab allocator: according to the pre-defined size, the allocated memory is divided into blocks of a specific length to completely solve the memory fragmentation problem.

3. memcache is in memory. When the allocated memory is full, some K/V data will be deleted according to certain rules. After restart, all data will be lost.

4. Expiration Policy-memcache is specified at set time. For example, set key1 0 0 8 never expires. Redis can be set through expire.

5. The maximum storage object supported by memcached is 1 MB. Its memory allocation is quite special, but this allocation method is also based on performance considerations. A simple allocation mechanism can be easier to recycle and reallocate, saving CPU usage. If the value is larger than 1 MB, You need to split it.

6. the maximum length of the key accepted by memcached is 255 characters.

7. A set command and a GET command are sent at the same time for the same data. They do not affect each other. However, after a GET command is sent, it may be replaced by another set during processing, and the subsequent set will overwrite the previous one, however, memcached 1.2.5 and later versions provide gets and CAS commands to solve the above problems. If you use the gets command to query the item of a key, memcached returns a unique identifier for the current value of this item. If you overwrite this item and want to write it back to memcached, you can use the CAS command to send the unique identifier together to memcached. If the unique identifier of the item stored in memcached is the same as that provided by you, your write operation will succeed. If another process modifies this item during this period, the unique identifier of the item stored in memcached will change, and your write operation will fail.

8. No authentication is required, and authentication is considered a higher level problem.

9. The delete operation only sets the chunk to the delete State, so that the chunk will be used preferentially in the next use.

10. The flush operation is equivalent to an action that invalidates all items. Does not change the memory allocation of memcache.

11. The allocated memory of memcache will not be automatically cleared.

12. Memory pages allocated by memcache to a slab cannot be distributed to other slab instances.

13. flush_all cannot reset the Memory Page allocation pattern of memcache, but set it to expire for all items.

14. The maximum size of items (Key + value) stored in memcache is 1 MB, which is limited by 1 MB of page size.

15. Because memcache's Distributed ClientProgramUse HashAlgorithmThe obtained key modulo is implemented. Different languages may adopt different hash algorithms, and the same client program may use different methods, therefore, when multiple languages and modules share the same group of memcached services, You must select the same hash algorithm on the client.

16. When starting memcached, you can use the-M parameter to disable LRU replacement. When the memory is exhausted, add and set will return failure.

17. When memcached is started, the data storage volume is specified, which does not include the memory occupied by memcached and the management space set to save the data. Therefore, it occupies more memory than the specified memory allocation at startup.

 

Ii. redis

1. redis not only supports Simple K/V data, but also provides storage of data structures such as list, set, and hash.

2. redis supports data backup, that is, data backup in master-slave mode.

3. redis supports data persistence. Data in the memory can be stored on the disk and loaded again during restart.

4. redis has certain database features.

5. redis data can be stored on the hard disk, and there is basically no expiration policy.

6. redis has a fatal defect. When the memory is full, the CPU usage of dump data is 100%.

7.

Iii. Differences between memcache and redis

    1. In redis, not all data is stored in the memory, which is the biggest difference from memcached.
    2. Redis has many database features, or is a database system, while memcached is just a simple K/V cache.
    3. All their extensions need to be cluster; implementation methods: master-slave and hash.
    4. Memcached has higher performance than redis in data of more than kb.
    5. For memory usage efficiency and simple key-value storage, memcached memory usage is higher. If redis uses the hash structure for key-value storage, due to its combined compression, the memory usage is higher than that of memcached. Of course, this is related to your application scenarios and data features.
    6. If you have requirements on data persistence and data synchronization, we recommend that you choose redis because memcached does not have these two features. Even if you just want to upgrade or restart the system and the cache data will not be lost, it is wise to choose redis.
    7. Redis and memcache have little difference in writing performance, especially in terms of reading performance, especially in terms of batch reading performance.

 

 

 

4. Other distributed caches

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.