Home > Database > Redis > Which one is better, mongodb or redis?

Which one is better, mongodb or redis?

silencement
Release: 2019-06-14 16:02:07
Original
4844 people have browsed it

Which one is better, mongodb or redis?

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 type of non-relational database and is often used as a cache.

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.

Advantages of redis

1. Supports a variety of data structures, such as string (string), list (double linked list), dict (hash table), set (set), zset (sorting 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.

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.

Advantages of mongodb

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 It will be written to the memory first and then persisted to the hard disk. However, MongoDB uses pre-allocated space to prevent file fragmentation, so MongoDB's data files are very large.

The biggest features of mongodb

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

The above is the detailed content of Which one is better, mongodb or redis?. 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