04redis interview Collection

table of Contents

1.Redis Profile

1.1Redis implementation of the principle of

1.2Redis common data types

2. Query a fixed prefix Key from massive amounts of data in

3. How to implement a distributed lock by redis

3.1 How to solve the Distributed Lock

After using the 3.2redis2.2

4. How to implement asynchronous queue

4.1 One to One

4.2-to-many

5.redis persistence

5.1Redis How do persist

RDB endurance of

AOF persistence

5.2RDB and the advantages and disadvantages of AOP

5.3 Mixed mode backup

6.redis synchronization mechanism

6.1 synchronous master-slave principle

6.2 Full synchronization process

6.3 Incremental synchronization

6.4redis Sentinel mode (Redis Sentinel)

6.5 protocol rumors Gossip

Principle of cluster 7.redis

Hash data issue inclined ring

8. Conclusion


1.Redis Profile

Redis and Memcache difference?

Redis Why so soon?

1.1Redis implementation of the principle of

Multiple IO multiplexing

1.2Redis common data types

Redis underlying data type

 

2. Query a fixed prefix Key from massive amounts of data in

First ask how much is the amount of data.

We use the following figure ways.

The client waits 30 seconds left

 

3. How to implement a distributed lock by redis

3.1 How to solve the Distributed Lock

How to solve the problem of long-term effective setnx

What problems will arise in the above code it?

If after SETNX, hang up the code, not the logic behind the implementation.

After using the 3.2redis2.2

 

4. How to implement asynchronous queue

4.1 One to One

There is no other way to achieve queue it? Have!

Left waiting for news, push the right message.

4.2-to-many

Want to solve this problem, we need to use a professional MQ

 

5.redis persistence

5.1Redis How do persist

RDB endurance of

Find our redis.conf files in the root directory redis installation.

We search save

900 represents the write command once in the 900s, will produce 1 snapshot.

300 represents the write command once in the 300s, will have a snapshot, if it is 0 <number of changes <10, will wait until after the 900s to do the backup.

60 shows in the 60s and 1w-line writing, we will conduct a backup.

stop-writes-on-bgsave-error yes indicate when the backup process error, the main process to stop new write operations to protect persistent data consistency.

rdbcompression no representation rdb file backup, file backup when rdb, the file is compressed before the backup. We set no.

redis system will periodically back up files in file dump.rdb

 

Shown, perform the save save exit connection may generate rdb file see above.

Rdb delete files, execute lastsave, returns the timestamp of the last saved rdb file.

We perform bgsave, re-save a copy, you will find lastsave timestamp changed.

 

Automatic trigger RDB

AOF persistence

Similarly, enter the file redis.conf

Search appendonly set to yes, it will take effect.

Search appendfsync, the default backup once per second. After configuration is complete restart redis service

Restart when we can see that it sends a shutdown instruction, the instruction after feeling suffocated save, save here in our rdb file.

When we perform a write operation, you will see the directory generated aof file.

 

5.2RDB and the advantages and disadvantages of AOP

5.3 Mixed mode backup

redis4.0 after the launch.

 

6.redis synchronization mechanism

The benefits of using pipeline

6.1 synchronous master-slave principle

6.2 Full synchronization process

6.3 Incremental synchronization

6.4redis Sentinel mode (Redis Sentinel)

6.5 protocol rumors Gossip

 

Principle of cluster 7.redis

Clockwise key stored on the nearest node, such as ObjectB is stored on NodeB

The following diagram, if Ben collapse NodeC services, our object will be stored on the next table clockwise NodeD server.

The following diagram, if we add NodeX, will not affect other nodes Node, we only need to reposition the NodeX node in Object.

Hash data issue inclined ring

The introduction of virtual nodes to solve the problem of data skew

 

8. Conclusion

redis and Memcache

Multi-channel multiplexing io

Common type

Massive Data Filters key

Simple distributed lock

Asynchronous queue

Persistence: RDB, AOF, mixed

AOF: redis master-slave, redis Sentinel, redis clusters.

  

Published 55 original articles · won praise 91 · views 110 000 +

Guess you like

Origin blog.csdn.net/qq_42035966/article/details/104764120