Redis interview routine dismantling series (1)


Redis interview routine dismantling series (1)

Foreword: at present, the knowledge content related to redis has become a regular customer in the back-end interview. Mastering and understanding redis can greatly increase your interview scores. In addition, it is not advisable to memorize standard answers by rote if you want to stand out in the interview. In this series, the small blackboard will be interview oriented, connecting the relevant knowledge of redis to help you to firmly grasp the small heart of the interviewer in the interview~

Redis interview routine dismantling series (1)

Don’t say much, let’s get to the point! Let’s simulate the real interview scene step by step. Readers can also try to answer and see what the interviewers are facing“Torture”What kind of answer would you give.

Q1: I see that you have used redis in your resume. Can you tell me something about what you know? Or talk about your understanding of redis

analysis: this question is the most common warm-up question, but it should not be underestimated, because the content you answer will be the main entry point for the interviewer, so you must answer what you have mastered, you can not fully understand,But it’s very important to make sure that the points you mention are clear! And the proposal points to answer, will appear more organized, is a big bonus!

A: Well, redis actually has a lot of usage scenarios, such as caching, leaderboard, and common attention list

In fact, when it comes to redis, there are several features that impress me

  • First, redis is single threaded
  • Second, redis is based on memory and is very fast
  • Thirdly, redis provides a rich data structure

analysis:Generally speaking, answering the above points can provide a good entry point for the interviewer. The interview is an interactive process. How to introduce the interviewer into your pre designed one“trap”Chinese is a kind of knowledge. As long as you are ready, you are not afraid to ask, but you are not afraid to ask~

Q2: you mentioned that redis is single threaded. Why is it so fast?

analysis:This question can be regarded as a high-frequency question in redis interview, so how to answer it and reflect your own thinking is very important. Because the interviewer may have asked dozens of people this question, if you follow the so-calledStandard answerTo answer, that would not leave a deep impression on the interviewer. To answer this question, first of all, what does redis single thread mean? In fact, the core modules of redis are single threaded, not all of them are single threaded,Redis 6.0 supports multithreading, which means that you have the driving force of autonomous learning。 Secondly, it is necessary to explain that the core module is single threaded, so how to ensure the speed of redis? According to this idea, we can answer the questions separately and expand it.

A: The single thread of redis actually means that the core module for executing redis commands is single threaded, that is, file event processor, which is mainly composed of four parts: socket, IO multiplexing, file event dispatcher and event processor

Redis interview routine dismantling series (1)

alsoRedis 6.0 actually supports multithreading to improve performance。 There are three main reasons why redis is fast

  • First, redis is based on memory, and the data is stored in memory, which is very fast
  • Second, the IO model of redis is non blocking io
  • Thirdly, the single thread of redis core module can avoid the overhead of thread switching

Q3: now that I have talked about IO, what do you know about IO model? Tell me more about it?

analysisThe question of IO model is also a frequent interviewer. Most students may answer the questions of IO model, such as blocking IO, non blocking IO and IO multiplexing, and then swing the concept and spread it out with both hands, giving the interviewer the impression that you are reciting the text with me. Naturally, such an interview can’t achieve good results,The answers the interviewer wants to hear include your own thoughts and conclusions,In this way, your answer can be distinguished to a certain extent. Many students are very confused about such conceptual things as synchronous blocking and synchronous non blocking io. In fact, it is not so difficult. Just look at it

A: In fact, the IO process mainly includes two stages

  • In the first stage, wait for the data to be ready
  • In the second stage, the data is copied from the kernel space to the application address space

IO is classified according to the different performance of these two stages

  • In the first stage, blocking isBlocking IO,Does not block direct return; otherwisenon-blocking io
  • In the second phase, blocking isSynchronous IO, asynchronous if not blockedIO
  • Multiplexing IO is actually responsible for multiple sockets through polling mechanism

Supplement: it is difficult for many beginners to understand synchronous blocking IO, synchronous non blocking IO, asynchronous IO, IO multiplexing, etc., and the quality of the articles on the network is uneven, which is easy to mislead the readers. The intimate small blackboard at the back will specially write an article about IO to help you easily deal with this test in the interview

Redis interview routine dismantling series (1)

Q4: since redis is single threaded, how does it use multi-core?

A: Multiple cores can be used by opening multiple redis instances

According to the first two points you have raised, the question you often ask is almost like this. The key point is actually the data structure part of redis. There are basic data structures such as hash, list, set, and so on, as well as high-level data structures such as hyperlogger and bloon filter.

The usage of these data structures and the underlying principles and implementation are often asked in the interview process. A good answer is a very eye-catching bonus. In the next round of confrontation, how will the interviewer examine these knowledge points? What are the routines in answering these questions?

If you want to know what’s going on, please point your fingers and pay attention to the small blackboard~