当前位置:网站首页>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
边栏推荐
- 数组静态初始化,遍历,最值
- 复现 ASVspoof 2021 baseline RawNet2
- 存储、计算、分布式计算篇(收集整理适合小白)
- Supervisor deployment (offline deployment requires downloading the deployment package in advance)
- FRP reverse proxy deployment
- Radio and multi selection buttons of swing components
- Angr(十)——官方文档(Part1)
- 测试计划、测试方案
- Several common network diagnostic commands
- 4. Children next door will know all kinds of shell symbols {}[], etc
猜你喜欢
随机推荐
shortest-unsorted-continuous-subarray
7. Shell practical gadget cut, etc
Attention is all you need 论文精读笔记 Transformer
4.隔壁小孩都会的,各种shell符号{}[]等
Deploy master-slave database
User preferences
Notes on building dompteur container
Vscode latex workshop set xelatex compilation
Angr (VII) -- angr_ ctf
Software test notes, test case design
The ultimate summary of jsonobject parsing JSON format
2. Introduce the deployment of lamp platform +discuz Forum
String longest common prefix
After switching the shell command line terminal (bash/zsh), CONDA cannot be used: command not found
数组静态初始化,遍历,最值
21. Merge Two Sorted Lists
Array static initialization, traversal, maximum value
Supervisor部署(离线部署需要提前下载部署包)
Mouse monitor, Paintbrush
Angr (IX) -- angr_ ctf









