Home > Database > Redis > Which one is better between redis and mongodb?

Which one is better between redis and mongodb?

anonymity
Release: 2019-06-05 16:22:10
Original
2891 people have browsed it

What is Redis?

Redis is an open source log-type, Key-Value non-relational database written in ANSI C language, supports network, can be memory-based and persistent, and provides APIs in multiple languages. redis is a key-value storage system. Redis is a non-relational database that is often used as a cache.

Which one is better between redis and mongodb?

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

Same as memcached, in order to ensure efficiency, data is cached in memory. The difference is that redis will periodically write updated data to disk or write modification operations to additional record files, and on this basis, master-slave (master-slave) synchronization is achieved.

Redis has the following advantages:

1. Supports a variety of data structures, such as string (string), list (double linked list), dict (hash table) , set (set), zset (sorted set), hyperloglog (cardinality estimation)

2. Supports persistence operations, and can persist aof and rdb data to disk for data backup or data recovery. , a better way to prevent data loss.

3. Support data replication through Replication. Through the master-slave mechanism, data can be replicated synchronously in real time, and multi-level replication and incremental replication are supported. The master-slave mechanism is an important means for Redis to perform HA.

Single-threaded request, all commands are executed serially, and there is no need to consider data consistency issues in concurrent situations.

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

5. Supports simple transaction requirements, but there are few usage scenarios in the industry and it is not mature.

Disadvantages of Redis:

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

2. It supports simple transaction requirements, but there are few usage scenarios in the industry and it is not mature, which has both advantages and disadvantages.

3.Redis consumes more memory on the string type. You can use dict (hash table) to compress storage to reduce memory consumption.

4.Mc and Redis are both Key-Value types, which are not suitable for establishing relationships between different data sets, nor are they suitable for query searches. For example, the matching operation of redis' keys pattern is a disaster for the performance of redis.

What is MongoDB?

MongoDB is a database based on distributed file storage. Let me first explain the document database, which can store data of xml, json, and bson types. At the same time, MongoDB is written in C language. Designed to provide scalable, high-performance data storage solutions for WEB applications. It is a product between a relational database and a non-relational database. It is the most feature-rich among non-relational databases and is most similar to a relational database.

The data structure it supports is very loose and is a bson format similar to json, so it can store more complex data types. The biggest feature of Mongo is that the query language it supports is very powerful. Its syntax is somewhat similar to an object-oriented query language. It can almost implement most functions similar to single-table queries in relational databases, and it also supports indexing of data.

Mongodb is different from mysql. Every update operation of mysql will be written directly to the hard disk, but mongo will not. As an in-memory database, data operations will be written to the memory first and then persisted to the hard disk. , but MongoDB uses pre-allocated space to prevent file fragmentation, so MongoDB's data files are very large.

The characteristics of MongoDB are:

(1) Document-oriented (2) High performance (3) High availability (4) Easy to expand (5) Rich query language

The above is the detailed content of Which one is better between redis and mongodb?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template