The difference between Redis, MongoDB, and memcached

Source: Internet
Author: User
Tags memcached

Redis (in-memory database)

is a Key-value storage system (in-fabric cache, high-performance Key-value database). Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), Zset (sorted set-ordered collection), and hash (hash type). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis.

MongoDB (NoSQL database)

is a product between a relational database and a non-relational database (a database based on Distributed file storage), which is the most versatile and most like relational database in a non-relational database. The data structure he supports is very loose and is a JSON-like Bson format, so you can store more complex data types. MONGO's biggest feature is that the query language he supports is very powerful, and its syntax is a bit like an object-oriented query language that almost implements most of the functionality of a relational database single-table query, and also supports indexing of data.

Memcached (Memory Cache)

is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It improves the speed of dynamic, database-driven Web sites by caching data and objects in memory to reduce the number of times a database is read. Memcached is based on a hashmap that stores key/value pairs. Its daemon (daemon) is written in C, but the client can write in any language and communicate with the daemon through the memcached protocol.

1. Features

1.1 Redis

Supports multiple data structures such as String (string), list (doubly linked list), Dict (hash table), set (set), Zset (sort set), Hyperloglog (cardinality estimation);
Support persistent operation, AOF and RDB data can be persisted to disk, so as to carry out data backup or data recovery operation, better prevent data loss means;
Support through replication data replication, through the master-slave mechanism, can be real-time synchronous replication of data, support multi-level replication and incremental replication, master-slave mechanism is the 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 situation;
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.

Redis can only use single-threaded, performance is limited by CPU performance, so the single-instance CPU can reach 5-6wqps per second (depending on data structure, size and server hardware performance, the daily environment of the QPS peak around 1-2w);

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

Support (snapshot, AOF): dependent on the snapshot for persistence, AOF enhances the reliability while the performance has impact;

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

Both MC and Redis are key-value types, are not suitable for establishing relationships between different datasets, and are not suitable for query search. For example, the Redis keys pattern This matching operation, the performance of Redis is a disaster;

Redis has added its own VM features after the 2.0 release, breaking the limits of physical memory, and setting an expiration time for key value (similar to memcache);

Redis transaction support is weak and can only guarantee that each operation in a transaction is executed consecutively.

1.2 MongoDB

Suitable for storage of big data, relying on operating system VM to do memory management, eat memory is also more severe, services do not and other services together;

Support rich data expression, index, most similar relational database, support query language is very rich;

Support Master-slave,replicaset (internal use of Paxos election algorithm, automatic fault recovery), auto sharding mechanism, the client shielded the failover and segmentation mechanism;

From the 1.8 version, the Binlog method is used to support the reliability of persistence.

MongoDB does not support transactions;

MongoDB has built-in data analysis capabilities (MapReduce), others do not support

1.3 Memcached

The multi-core advantage can be leveraged to achieve a very high single-instance throughput of hundreds of thousands of QPS (depending on key, value byte size, and server hardware performance, and the peak of QPS in the daily environment around 4-6w). Suitable for maximum carrying capacity;
Supports direct configuration for session handle.

Supports only simple KEY/VALUE data structures, unlike Redis, which supports a wide variety of types;
Cannot be persisted, the data cannot be backed up, can only be used for cache use, and the data is all lost after reboot;
Data synchronization cannot be performed and data in the MC cannot be migrated to other MC instances;
Memory allocation uses the slab allocation mechanism to manage 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 can modify the maximum available memory, using the LRU algorithm.

2. Application Scenario

2.1 Redis
It is applicable to the high requirement of reading and writing efficiency, complicated data processing business and high security requirements (such as the count of Sina Weibo and the partial system of Weibo release, which is very high for data security and reading and writing requirements).
2.2 MongoDB
Mainly solve the massive data access efficiency problem.
2.3 Memcached
Dynamic system to reduce database load, improve performance, cache, suitable for read less write, Big data volume (such as Renren large query user information, friend information, article information, etc.);
Used to reduce database load in dynamic system, improve performance, cache, improve performance (for read and write less, for a large amount of data, you can use sharding).

The difference between Redis, MongoDB, and memcached

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.