Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Advantages and disadvantages of redis and mongodb

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will bring you an article that discusses the advantages and disadvantages of redis and mongodb. The editor thinks it's pretty good, so I'll share it for you as a reference. Let's follow the editor and have a look.

What is Redis?

Redis is an open source log-type, Key-Value non-relational database written in ANSI C language, which supports network, memory-based and persistence, and provides API in multiple languages. Redis is a key-value storage system. Redis is a type of non-relational database and is often used as a cache.

Similar to Memcached, it supports relatively more value types, including string (string), list (linked list), set (collection), zset (sorted set-ordered collection), and hash (hash type). These data types support push/pop, add/remove, and take intersection union and difference sets, and richer operations, and these operations are atomic. On this basis, redis supports a variety of different sorting methods.

Like memcached, data is cached in memory for efficiency. The difference is that redis will periodically write updated data to disk or modify operations to additional record files, and on this basis to achieve master-slave (master-slave) synchronization.

Redis has the following advantages:

1. Support multiple data structures, such as string (string), list (two-way linked list), dict (hash table), set (collection), zset (sorting set), hyperloglog (cardinality estimation)

two。 Support persistence operation, aof and rdb data can be persisted to disk, thus data backup or data recovery and other operations, a better means to prevent data loss.

3. Support data replication through Replication, through master-slave mechanism, real-time synchronous data replication, support multi-level replication and incremental replication. Master-slave mechanism is an important means for Redis to carry out HA.

Single-thread request, all commands are executed serially, and data consistency does not need to be considered in the case of concurrency.

4. Support pub/sub message subscription mechanism, which can be used for message subscription and notification.

5. Simple transaction requirements are supported, but the industry uses few scenarios and is not mature.

Disadvantages of Redis:

1.Redis can only use single thread, and its performance is limited by CPU performance, so the maximum CPU of a single instance can reach 5-6wQPS per second (depending on data structure, data size and server hardware performance, the peak of QPS in daily environment is about 1-2w).

two。 Simple transaction requirements are supported, but the industry uses few scenarios and is immature, which is both an advantage and a disadvantage.

3.Redis consumes more memory on the string type, so you can use dict (hash Table) compressed storage to reduce memory consumption.

Both 4.Mc and Redis are Key-Value types and are not suitable for establishing relationships between different datasets or for query and search. For example, the matching operation of redis's keys pattern is a disaster for the performance of redis.

What is MongoDB?

MongoDB is a database based on distributed file storage. First explain the database of the document, that is, you can store the data of the xml, json, and bson types. At the same time MongoDB is written by C++ language. Designed to provide scalable high-performance data storage solutions for WEB applications. It is a product between relational database and non-relational database, which is the most functional and most like relational database in non-relational database.

It supports a very loose data structure, which is similar to json's bson format, so it can store more complex data types. The most important feature of Mongo is that the query language it supports is very powerful, and its syntax is somewhat similar to the object-oriented query language. It can almost achieve most of the functions similar to the single table query of relational database, and also supports the establishment of data indexing.

Mongodb is different from mysql, every update operation of mysql will be written directly to the hard disk, but mongo will not, as a memory database, the data operation will be written to memory first, and then persisted to the hard disk, but MongoDB uses pre-allocated space to prevent file fragments, so the data file of MongoDB is very large.

The characteristics of MongoDB are:

(1) document oriented (2) high performance (3) high availability (4) easy extensibility (5) rich query language

The above is the knowledge summary of the advantages and disadvantages of redis and mongodb, the content is more comprehensive, the editor believes that there may be some knowledge points that we may see or use in our daily work. I hope you can learn more from this article.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report