What is the difference between Redis and memcached?

Source: Internet
Author: User
Tags redis cluster
Redis also has key-value to store, can exist in memory, but also support persistent storage, and Redis cluster, distributed deployment, mirror synchronization are native support, More convenient than memcached (memcached also have to write their own consistency hash algorithm to determine the value of a key corresponding to which memcached node, very troublesome), then memcached what is the use?
Why not just use Redis instead of memcache?
(I see that there are still a lot of PHP tutorials, textbooks are talking about memcached, the mention of Redis is still relatively small, I also look at others blog to know there is such a thing.) )

Reply content:

Redis also has key-value to store, can exist in memory, but also support persistent storage, and Redis cluster, distributed deployment, mirror synchronization are native support, More convenient than memcached (memcached also have to write their own consistency hash algorithm to determine the value of a key corresponding to which memcached node, very troublesome), then memcached what is the use?
Why not just use Redis instead of memcache?
(I see that there are still a lot of PHP tutorials, textbooks are talking about memcached, the mention of Redis is still relatively small, I also look at others blog to know there is such a thing.) )

It depends on the situation!

    • Memcachedis a multi-threaded non-blocking IO multiplexing network model; Redis using a single-threaded IO multiplexing model

    • MemcachedHow to use a pre-allocated memory pool, and Redis how to store data using the field request for memory

    • MemcachedServer-side is completely independent of each other; Redis plan to build support for the cluster on the server side

    • MemcachedMulti-core can be used; Redis only single-core

In summary, using simple key-value storage, Memcached the memory utilization is higher, and when key/value more data type support is needed, it is Redis more appropriate to use. Hope to help you

Redis is replacing memcached, but you need to know that Redis is a new thing, and it takes time for a large system to replace the whole.
The Redis cluster is currently used by Weibo.

Xie Invited ~ ~

Before out of the net, now to the title of some of my personal views and some reference materials, feel useful to take it, wrong also welcome everyone to support, feel good on the point of praise ~ ~ ~

First of all, let me explain one point: the existence is reasonable, and some people use it to show that it has its own value.

Briefly

Memcached and Redis are very similar: all in-memory database, data storage in memory, through TCP direct access, the advantage is fast, high concurrency, the disadvantage is that the data type is limited, the query function is not strong, generally used as a cache.

So the Lord said memcached things Redis can do, then why memcached still someone use? That's because they're not completely replaceable, they have their own pros and cons:

Memcached

Advantages of memcached:

    • The memcached can take advantage of multicore advantages, with a very high single-instance throughput of hundreds of thousands of QPS (depending on key, the byte size of value, and server hardware performance, which is around 4-6w in the daily environment).

    • Suitable for maximum carrying capacity, effective decompression for the server.

    • Supports direct configuration for session handle.

    • Fewer pits for configuration maintenance.

Limitations of memcached:

    • The data structures are simple and single, supporting only simple key/value data structures, unlike Redis, which supports rich data types.

    • Cannot be persisted, data cannot be backed up, it can only be used for cache use, and data is lost after reboot.

    • Data synchronization cannot be performed and data in the MC cannot be migrated to another instance of MC.

    • memcached memory allocation using slab
      The allocation mechanism manages memory, which causes memory utilization to decrease when the value size distribution is large, and causes problems such as kicking out when low utilization occurs. Users need to focus on value design.

    • Memcached service-side native does not support horizontal scaling, the client must write a cache distribution policy to implement distributed caching, and due to the inability to synchronize data, a single machine failure in the production environment can affect some of the business operations.

Redis

Advantages of Redis:

    • supports a variety of data structures, such as String,
      List (doubly linked list), Dict (hash table), set (set), Zset (sort set), Hyperloglog (cardinality estimate), and so on.

    • Support persistent operation, AOF and RDB data can be persisted to disk, so as to carry out data backup or data recovery operations, better prevent data loss means.

    • Support the data replication through replication, through the master-slave mechanism, can be in real-time synchronous replication of data, support multi-level replication and incremental replication, master-slave mechanism is an important means of Redis ha.

    • Single-threaded requests, all commands are executed serially, and there is no need to consider data consistency issues in the concurrency scenario.

    • Support PUB/SUB Message subscription mechanism, can be used for message subscription and notification.

    • Supports simple transaction requirements, but industry usage scenarios are rare and immature.

Limitations of Redis:

    • Redis can only use a single thread and performance is limited to CPU performance, so the single instance CPU can reach 5-6wqps per second (depending on data structure, data size and server hardware performance, and the QPS peak in daily environments is around 1-2w).

    • Support simple transaction requirements, but the industry use of the scene is very small, immature, both advantages and disadvantages.

    • Redis consumes more memory on string types, and can use Dict (hash table) to compress storage to reduce memory consumption.

Summarize

In my opinion, Redis has a database feature in many ways, or a database system, and memcached is simply a k/v cache.

and whether to use Redis or memcached this or to look at the needs of the Lord, because simply to do the cache, memcached is enough to deal with most of the demand, the advent of Redis just provides a better choice, but does not mean that Redis can completely replace Memcached, or that sentence, see what your needs are.

According to the new and old technology, Redis is more new than memcached, but mature woke up to say, memcached should be better, and now the trend has started to switch to MongoDB, because the database features of Redis, MongoDB better.

Many companies use memcached in the cache strategy or the majority of, and then Redis, the last is MongoDB, found no, the latest technology in the company team application or need time, the old technology strategy is still a lot of company team in use, because the technology molding and stability is better, This is also the reason why memcached is mentioned more than Redis.

Look at the demand, see the Master

In fact, the performance is similar, but Redis performance will be slightly better.
Redis replaces memcached as a trend.

  • 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.