Linux operation and maintenance engineer interview questions (4)

Linux operation and maintenance engineer interview questions (4)

I wish you all the best of luck in finding the job you want.
Continuous learning will not be eliminated.
The earth doesn't explode, we don't take holidays.
Opportunities are always reserved for those who are prepared.
Come on, hit the workers!

1 Commonly used data types in redis

  • String: String, the most basic data type
  • List: list
  • Hash: hash object
  • Set: set
  • Sorted Set: an ordered collection, a score is added to the Set

2 There are several types of redis data persistence, what are the differences, and how to choose

Both rdb and aof

Aof is similar to mysql's binary log, it records all operations in the log. And rdb is the real stored data, which is equivalent to snapshotting all the data of redis in the memory to the disk.

If it is mainly used as a cache function, or can withstand the loss of data for a few minutes, usually the production environment generally only needs to enable RDB, which is also the default value; if the data needs to be stored persistently and cannot be lost at all, you can choose to enable RDB and AOF at the same time. It is generally not recommended to only enable AOF.

3 What are the architectural modes of redis

  • master-slave replication
  • Sentinel
  • Redis Cluster

4 What is cache avalanche? How to solve?

Definition: If the expiration time set by the cached data is the same, the cache will be invalidated at the same time within a certain period of time, and all requests will go to the database, which will cause the database to go down.

Solution:

Add a random value to the expiration time when caching, which will greatly reduce the cache expiration at the same time.

5 What is cache penetration? How to solve?

Definition: Cache penetration refers to querying data that must not exist. Due to a cache miss and for fault tolerance considerations, if the data cannot be found from the database, it will not be written into the cache. This will cause the non-existent data to be queried in the database every time it is requested, which loses the meaning of caching. A large number of data misses in the cache, causing requests to go to the database.

Solution:

Since the requested parameters are illegal (parameters that do not exist are requested every time), we can use a Bloom filter (BloomFilter) or a compression filter to intercept in advance. If it is illegal, the request will not be sent to the database layer!

When we can't find it from the database, we also set this empty object to the cache. The next time you request it, you can get it from the cache.

In this case, an empty object is generally set with a shorter expiration time.

6 What is cache breakdown? How to solve?

Definition: A certain hotspot key is constantly carrying high concurrency. When the hotspot key becomes invalid, the continuous high-concurrency access will break the cache and directly access the database, causing the database to go down.

Solution:

Set hotspot data to "never expire" plus a mutex. The above phenomenon is that multiple threads query the data of the database at the same time, then we can use a mutex to lock it on the first query data request, and other threads will go to this step if they cannot get the lock. Wait, wait for the first thread to query the data, and then put the data into redis cache. Later threads come in and find that there is already a cache, so they go directly to the cache.

Summary:
Avalanche is a large area of ​​key cache failure; penetration is that the cache key does not exist in redis; breakdown is a hotspot key in redis suddenly fails, and the ultimate victim is the database.

7 Why is redis so fast

  1. Completely based on memory, most requests are pure memory operations, very fast. Data exists in memory, similar to HashMap, the advantage of HashMap is that the time complexity of search and operation is O(1);
  2. The data structure is simple, and the data operation is also simple. The data structure in Redis is specially designed;
  3. Using a single thread avoids unnecessary context switching and race conditions, and does not consume CPU due to switching caused by multi-process or multi-threading. There is no need to consider various locks, there is no lock-release operation, and there is no possible reason. Performance consumption caused by deadlock;
  4. Use multiple I/O multiplexing model, non-blocking IO;
  5. The underlying models are different, the underlying implementation methods between them and the application protocol for communicating with the client are different. Redis directly builds the VM mechanism by itself, because if the general system calls the system function, it will waste a certain amount of time to move and request

8 Redis common commands

  • INFO: Display the current node redis running status information
  • SELECT: Switch databases, equivalent to the USE DBNAME command in MySQL
  • KEYS: View all keys under the current library, use this command with caution!
  • BGSAVE: Manually perform RDB persistence operations in the background
  • DBSIZE: returns the number of all keys under the current library
  • FLUSHDB: Forcibly clear all keys in the current database, use this command with caution!
  • FLUSHALL: Forcibly clear all keys in all databases of the current redis server, that is, delete all data. Use this command with caution!

9 Classification of SQL Statements

  • DDL: Data Definition Language data definition language
    CREATE, DROP, ALTER
  • DML: Data Manipulation Language data manipulation language
    INSERT, DELETE, UPDATE
  • DQL: Data Query Language Data Query Language
    SELECT
  • DCL: Data Control Language data control language
    GRANT, REVOKE, COMMIT, ROLLBACK

The name of the software developer: CRUD, corresponding to addition, modification and deletion

10 Multi-table query

  • Subquery: The query statement is nested in the SQL statement, the performance is poor, and the query is performed again based on the query result of a certain statement
  • Joint query: UNION
  • Cross connection: Cartesian product, cross join
  • Inner connection:
    Equivalent connection: Let the fields between tables establish a connection relationship with "equal value"
    Non-equivalent connection
    Natural connection: Remove the equivalent connection of repeated columns
  • Outer join:
    Left outer join: FROM tb1 LEFT JOIN tb2 ON tb1.col=tb2.col
    Right outer join: FROM tb1 RIGHT JOIN tb2 ON tb1.col=tb2.col
    Self-join: join query between this table and this table

example:

# 子查询,常用在WHERE子句中的子查询
SELECT Name,Age FROM students WHERE Age>(SELECT avg(Age)FROM teachers);

# 联合查询
SELECT Name,Age FROM students UNION SELECT Name,Age FROM teachers;

# 交叉连接,即笛卡尔乘积,利用cross join实现
select stuid,s.name st_name,s.age st_age,tid,t.name te_name,t.age te_age from teachers t cross join students s;

# 内连接inner join
select * from students s inner join teachers t on s.teacherid=t.tid;

# 左外连接,outer可以省略
select s.stuid,s.name,s.age,s.teacherid,t.tid,t.name,t.age from students s left outer join teachers t on s.teacherid=t.tid;

# 右外连接
select * from students s right outer join teachers t on s.teacherid=t.tid;

# 自连接
# 构建表
create table emp (id int auto_increment primary key,name varchar(20),leader_id int);
# 实现自连接
select e.name,l.name from emp e inner join emp l on e.leader_id=l.id;

The above interview questions are just a personal summary. Write whatever you think of, without any order. If there is anything wrong with the writing, please comment and leave a message, and I will correct it in time.

Original link: Linux operation and maintenance engineer interview questions (4)

Guess you like

Origin blog.csdn.net/qq_45520116/article/details/129338550