当前位置:网站首页>[redis series] redis learning 13. Redis often asks simple interview questions
[redis series] redis learning 13. Redis often asks simple interview questions
2022-04-23 12:02:00 【Little Devil boy Nezha】
Let's see redis Often ask common interview questions
Redis What is a ?
http://www.redis.cn/ redis The Chinese website gives a very clear and clear definition
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-5HZnf7He-1650460558149)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20210828092258505.png)]
-
Redis It's open source (BSD The license ) Of , Data structure storage system in memory
-
Redis Can be used as a database 、 Caching and message middleware
-
The supported data structures are 8 Kind of
character string (strings), hash (hashes), list (lists), aggregate (sets), Ordered set (sorted sets), bitmaps, hyperloglogs and geospatial
Use redis What are the benefits ?
- The data accessed is very fast ,redis The data is operated directly in memory
- Rich features : Available for caching , Message queue , wait
- Support 8 Kind of data type
Redis Why so fast ?
First redis It's single threaded , Many people think that a single thread must be slow , Multithreading must be fast , This is a misunderstanding
- redis Using multiple channels I/O Reuse model , Non blocking Of IO
- Using single thread , There will be no consumption of context switching , Don't think about locking and unlocking , There is no performance consumption of competing resources
- The data structure is simple , Above 8 Kind of data type , Master something without too much effort
- operation redis The data of , Basically in the proper operation memory , Must be quick
Redis Can it be persistent ? If you can , What are the ways of persistence ?
It can persist , Yes 2 Ways of planting , RDB and AOF , redis The default is to support RDB Persistence
- RDB Persistence mode
Writes a dataset snapshot in memory to disk within a specified time interval , This is the snapshot snapshot , When restoring a snapshot , Is to read the snapshot file into memory .
redis adopt fork Create a child process to do persistent actions

advantage
- Suitable for large-scale data recovery
- The requirement of data integrity is not high
Inferiority
-
Operations need to be performed at certain intervals , If redis Unexpected downtime , The last written data will be lost
-
fork The subprocess needs to occupy a certain space
-
AOF Persistence mode
AOF yes redis Another way of persistence , Log every write operation , take redis All write operations performed are recorded , Only additional files are allowed , Rewriting of files is not allowed

advantage
- Every operation reids Will be recorded , The integrity of the file is good
- Synchronize once per second , One second of data could be lost
- No synchronization , This is the most efficient
Inferiority
- Relative to data files ,aof The file will be much larger than rdb file , It's faster than rdb The files are slow
- aof Operating efficiency ratio rdb slow , therefore redis The default configuration is rdb Persistence
Redis What are the application scenarios ?
- Simple message queuing
Simple message queue for publishing and subscribing , Use to redis in List data structure , Can pass lpush and rpop Write and read messages , This only applies to simple message queues , If you have a lot of data , Require data consistency , Good performance, etc , Of course, professional message queuing components are preferred
- Used to cache
Access data that you often need to access redis in , And set up redis Maximum memory limit and deletion key The strategy of
- For counter
For example, web page visits , Like and so on ,redis Support self increasing and self decreasing operations , The data is all in memory , Very suitable for counting
- Do distributed locks
redis The order that comes with you SETNX , Naturally, it can be used as a distributed lock , It is used to control the orderly operation of multiple nodes , Of course redis I have provided RedLock For everyone to use
RedLock What is a
Redis The information provided by the official website is based on Redis How to implement distributed locks , It has the following characteristics :
- Fault tolerance
As long as most Redis If the node survives, it can provide services normally
- Safety features
RedLock Mutually exclusive access , There will always be only one redis The client can get the lock , Perform the operation
- Avoid deadlock
Final redis The client may get the lock , There will be no deadlock
- Make a leaderboard
Use zset Make a leaderboard ,top xx And so on
- Do common concern , Be a good friend around you
redis Provide a collection set , Can calculate the common friends , Common interests , And so on
Redis Delete expired key How is it handled ?
Yes 3 Ways of planting :
- Timed expiration
Timed expiration , Every time you set a key When , All for this key Set the corresponding timer , When this key ttl At maturity , Will this key Delete the
Every key When the expiration time is set, we need to get a timer , such It's very exhausting cpu resources , And then affect redis performance
- Expire regularly
Expire regularly , Is to set every other period of time , scanning redis Set the expiration time in key, And delete the expired key.
- Inertia expires
Inertia expires , Whenever you visit this key When , To judge this key Is it invalid , Delete when it fails , If you don't visit , Then this key It's always in memory , It takes up a lot of memory
Redis What is the essence of affairs ?
Is a collection of commands , All commands in a transaction are serialized , In the process of transaction execution , The commands are executed in order , They have
- Disposable
- Sequence
- exclusive
redis There is no concept of isolation level for transactions
redis Transaction , Execute the command like this
Put commands in transactions , Not immediately , But only when the execution order is initiated , adopt exec Trigger

redis It's a single instruction that guarantees atomicity , But transactions don't guarantee atomicity
The process of executing a transaction is like this :
- multi Open transaction
- Join the team with various orders
- exec Perform transactions
The transaction ACID What do you mean by separation ?
- Atomicity Atomicity
Atomicity refers to , A business is an indivisible whole , Or make it together , Or fail together
- Consistency Uniformity
Before and after the execution of the transaction , The integrity of the data must be consistent
- Isolation Isolation,
When multiple transactions are processed at the same time , Mutual interference , The complementary effect , Let's play
- Durability persistence
refer to , Once the transaction is committed , So the data affected is persistent
Redis What is the principle of master-slave replication ?
Slave Start successfully connected to master A... Will be sent later sync command
master After receiving the order , Start the background save process , At the same time, collect all commands received to modify the database set , After the background process is executed ,master The process will transfer the entire data file to slave , And complete a synchronization
Copy in full
slave Service received master After the data transmitted , Save it and load it into memory
Incremental replication
master Pass all the newly collected modified commands to slave , And complete synchronization
Once reconnected master node , A full synchronization is performed
What does sentinel mode do ?
Sentinel mode , Mainly for the realization of redis High availability of clusters
Because using master-slave replication , When redis When the host goes down , There is no way to elect a host , Sentinel mode can

The role of a sentry :
- By sending commands ,Redis The server returns monitoring status information , Including master and slave servers
- If the sentry detects that the primary server is down , Will automatically slave Switch master, Then notify other slave servers by publishing and subscribing , Modify the configuration file , Let him be the host
Subjective offline
If master Server down , Then one of the Sentinels will detect , The system does not execute immediately failover The process of , Just the current sentinel , Judge master Unavailable , This is Subjective offline
Objective offline
The general sentry in the cluster is also a cluster , If deployed 3 A sentinel
When the other two sentinels found master When the server is unavailable , Then there will be a vote between the Sentinels , We will write the specific voting algorithm later , The voting structure was initiated by a sentry , Conduct failover Failover operations , After successful switching , Through the publish and subscribe mode , Let each monitoring sentry switch its monitoring server to this master Server , This is Objective offline
redis Of through , breakdown , Avalanche problem can be seen in the previous article :【Redis series 】redis Learn twelve ,redis Cache penetration , Cache breakdown , Cache avalanche
Reference material :
Welcome to thumb up , Focus on , Collection
friends , Your support and encouragement , I insist on sharing , The drive to improve quality

Okay , That's it this time
Technology is open , Our mindset , It should be more open . Embrace change , Born in the sun , Try to move on .
I am a Little Devil boy Nezha , Welcome to like, pay attention to collection , See you next time ~
版权声明
本文为[Little Devil boy Nezha]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231158518091.html
边栏推荐
- ImportError: libX11.so.6: cannot open shared object file: No such file or directory
- Here comes the detailed picture and text installation tutorial of H5 game
- golang之笔试题&面试题01
- Link sorting of tutorials such as assembly language running environment setting
- Analyze the rules for the use of robots with good performance
- How imeu is associated with imcu (IM 5.5)
- Docker MySQL master-slave backup
- 软件测试基础DAY2-用例执行
- Chapter 4 is a tutorial on forced filling of in memory objects with IM enabled filling objects (IM 4.7)
- Database design of simple voting system
猜你喜欢

Idea code formatting plug-in save actions

Exploring the equipment and teaching of robot education

软银愿景基金进军Web3安全行业 领投CertiK 6000万美元新一轮投资

Relu function of activation function

PSCP 基本使用

Tan Xiang, CEO of Kechuang · Pera software: the essence of zero trust is digital security. To B should also deeply study the user's mind

编程辅助工具推荐:图片工具snipaste

After a circle, I sorted out this set of interview questions..
![Change exchange II - [leetcode]](/img/ad/33b13a004208d613c9a211fec9e5b1.png)
Change exchange II - [leetcode]

Nativeformysql connects to MySQL 8 prompt: 1251 - client does not support authentication protocol
随机推荐
Tclerror: no display name and no $display environment variable
第四章 为IM 启用填充对象之启用和禁用表空间的IM列存储(IM 4.5)
Im architecture: CPU architecture: SIMD vector processing (im-2.3)
Blog post navigation (real-time update)
Significance of actively participating in middle school robot competition
第二十五课 类的静态成员变量
Nacos Foundation (8): login management
Step function of activation function
第二十六课 类的静态成员函数
Force buckle - 1137 Nth teponacci number
ES6学习笔记二
Windows2008系统如何切换PHP版本
怎么进行固定资产盘点,资产盘点报告如何一键生成
初探 Lambda Powertools TypeScript
Cognition and R & D technology of micro robot
VMware虚拟机使用esxi 导出硬盘vmdk文件
5-minute NLP: text to text transfer transformer (T5) unified text to text task model
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
Nacos Foundation (6): Nacos configuration management model
MySQL 的主从复制配置