当前位置:网站首页>Differences between redis and mongodb
Differences between redis and mongodb
2022-07-25 10:32:00 【colours starry sky】
MongoDB More like MySQL, Support field Indexes 、 The cursor operation , Its advantage lies in the powerful query function , Good at query JSON data , It can store a lot of data , however Unsupported transaction .
Redis It's open source (BSD The license ) Of , Data structure storage system in memory , It can be used as a database 、 Caching and message middleware . It supports multiple types of data structures , Such as character string (strings), hash (hashes), list (lists), aggregate (sets), Ordered set (sorted sets) And scope query , bitmaps, hyperloglogs and Geographical space (geospatial) Index radius query . Redis Built in Copy (replication),LUA Script (Lua scripting), LRU Driving events (LRU eviction), Business (transactions) And different levels of Disk persistence (persistence), And pass Redis sentry (Sentinel) And automatic Partition (Cluster) Provide high availability (high availability)
Memory management mechanism
Redis All data is in memory , Write to disk regularly , When there is not enough memory , You can choose the specified LRU Algorithm delete data .
MongoDB Data exists in memory , from linux System mmap Realization , When there is not enough memory , Just put the hotspot data in memory , Other data is on disk .
Persistence mode
mongodb All of the data is actually stored on the hard disk , All data to be operated passes through mmap Mapping to an area of memory .
then ,mongodb Modify the data in this area , Avoid the piecemeal operation of the hard disk .
as for mmap Content on flush To the hard disk is the operating system , therefore , If ,mongodb After modifying the data in memory ,mmap data flush Before going to the hard disk , The system is down , The data is lost .
(mmap System calls are not designed solely for shared memory . It itself provides a different way of accessing ordinary files , Processes can operate on ordinary files like read and write memory .
mmap The system call enables the process to realize shared memory by mapping the same common file . After the normal file is mapped to the process address space , The process can access files just as it can access normal memory , No need to call . read(),write() Wait for the operation .mmap It doesn't allocate space , Just map the file to the address space of the calling process , Then you can use memcpy Wait for the operation to write the document , without write() 了 . Use... After writing msync() Synchronize , What you write is saved in the file . But there is no way to increase the length of the file in this way , Because the length to map is calling mmap() It's time to decide .)
redis:
It is a real in memory database .
Supported data structures
Redis The data structure supported is rich , Include hash、set、list etc. .
MongoDB The data structure is relatively simple , But support rich data expression , Indexes , Most similar to relational databases , The supported query languages are very rich .
Data volume and performance
When there is enough physical memory ,redis>mongodb>mysql
When physical memory is not enough ,redis and mongodb Will use virtual memory .
In fact, if redis To start virtual memory , It's obvious to either add memory , Or you change the database .
however ,mongodb Dissimilarity , as long as , Business guarantees , Read write ratio of hot and cold data , Make the hot data in physical memory ,mmap Less exchange .
mongodb Still guaranteed performance .
performance
Both of them have high performance , It should not be a bottleneck .
reliability
Both support persistence .
Transaction support
Redis Transaction support is weak , It can only guarantee the continuous execution of each operation in the transaction
mongodb Unsupported transaction
边栏推荐
猜你喜欢
随机推荐
Angr (III) - angr_ ctf
软件测试笔记,测试用例设计
3.信你能理解的!shell脚本之循环语句与函数,数组,冒泡排序
Small knowledge of common classes
Angr(五)——angr_ctf
PyTorch 代码模板 (CNN)
MySQL offline deployment
Array static initialization, traversal, maximum value
二、unittest框架主要做什么
Angr(一)——安装
Dynamic planning, shopping list problem
测试基本概念
Angr(六)——angr_ctf
Angr (IX) -- angr_ ctf
When installing mysql, string the service installation failure > mysql80 startup failure
Multithreading deadlock and synchronized
Mouse monitor, Paintbrush
bug要素
Detailed explanation of chrome developer tools
Pytorch calculates the loss for each sample in the batch








