Redis memcached comparison

Source: Internet
Author: User
Tags database sharding

Redis memcached comparison

Memcached is multi-thread. When calculating some statistical data, there will be a slight loss of efficiency due to the lock relationship.

Redis is a single thread. The author believes that memory storage is fast enough and does not require multithreading. redis has a new thread to perform some management work, such as cache failure.

Memcached uses inertia to expire. when the key is accessed, it determines whether it is invalid. If the key is not accessed, it may be stored in the memory until the memory is insufficient, it will be replaced only when low-access key-free space is searched. memcached does not use or use less logic to determine which keys are not used. Instead, it compares all keys because memcached divides keys into different blocks, so his comparison is to compare which keys in a block are used less, so it is not accurate,

Therefore, memcached must ensure key consistency.

Redis has multiple ways to manage invalid cache, there are inertia methods, there are random small data clearing, and when the memory is not enough, violent Elimination



Redis has two permanent mechanisms, but there are some problems.

One is a memory snapshot. The principle is to copy one minute of memory and then write it to the hard disk. This requires that the memory usage of redis cannot exceed 1/2 of the physical memory. If the memory usage exceeds, the virtual memory will be used. in addition, there will be a large number of reads and writes during the snapshot process. If the system crashes, data will be lost.

The second is to read and write logs, which is the same as the database, but there will be IO operations, and the log file will be large, recovery will be slow, and the overall performance will also be slow


In memory allocation, memcached applies for memory before use, to save the efficiency of applying for memory from time to time, but this will cause a great waste of memory. When memcached is started, the block size is 1 MB, and the block size is divided into several k or dozens of k blocks. during use, these blocks are suitable according to the value size, if the value is about the same size, a lot of blocks will be wasted. therefore, memcached uses the space-for-time method, but it occupies a large amount of memory.


Redis is a real-time memory application, so there will be no memory waste, but the speed must be a little slower than memcached

Memcached has distributed APIs, which must be written by redis itself,

To sum up

I personally think that memcached is only a cache system. It is suitable for calling data from a database and writing data to memcached. The customer needs to read data from memcached and the key value is stable. The value should be of different sizes.

It is suitable for pure read operations such as search.

Redis has write operations, but there are some problems. If you only use one server, you can use the memory snapshot as a local database. But for multiple servers, there must be a database sharding policy, however, redis provides implementation possibilities for fast read/write.

Suitable for Forum applications.

But for forums, is mangodb better?

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.