Too liver! Tencent Cloud God's code "redis in-depth notes" is all the essence

Preface

As a bald person of code at this time, he is definitely no stranger to Redis. If you haven't used Redis, I'm really embarrassed to go out for an interview, maybe how many times I have been hanged by the interviewer.

After all, Internet companies and some startups now use Redis, such as Amazon, Google, Ali, and Tencent. It shows that it is really necessary to be proficient in the use of Redis.

Therefore, today, I shared the "redis depth notes" coded by Tencent Cloud. The content of the notes did not say a word of nonsense. The whole article is the essence of it!

If you need the help of a small partner who needs the PDF version of Redis Deep Notes, you can get it for free by adding a small assistant VX (gyhycx7980) as shown in the picture below!

 

 

PART1: Redis in-depth notes opening

1. What can Redis be used for?

  • Thoughts from the Redis interview
  • What can Redis do?

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

2.Redis basic data structure

  • Redis installation
  • Redis basic data structure
  • General rules for container data structures
  • Some thoughts on the use of Redis

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

If you need the help of a small partner who needs the PDF version of Redis Deep Notes, you can get it for free by adding a small assistant VX (gyhycx7980) as shown in the picture below!

PART2: Summary of the application of Redis

1. Distributed lock

  • Distributed lock
  • Timeout problem
  • Reentrancy

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

2. Delay queue

  • Asynchronous message queue?
  • What if the queue is empty?
  • Queue delay
  • Idle connections are automatically disconnected
  • Lock conflict handling
  • Implementation of Delay Queue
  • further optimization

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

3. Bitmap

  • Basic use
  • Statistics and lookup
  • Magic instruction bitfield

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

4.HyperLogLog

  • Instructions
  • What does pf pf mean?
  • What occasions is pfmerge suitable for?
  • Precautions
  • HyperLogLog implementation principle
  • Why is the memory usage of pf 12k?

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

5. Bloom filter

  • What is a Bloom filter?
  • Bloom filter in Redis
  • Basic use of Bloom filter
  • Precautions
  • Principle of Bloom filter
  • Space occupancy estimate
  • How will the false positive rate change when the actual element exceeds?
  • What should I do if Redis4.0 is not available?
  • Other applications of Bloom filters

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

6. Simple current limit

  • How to use Redis to implement a simple current limiting strategy?

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

7. Funnel current limit

  • Redis-Cell
  • Some thinking

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

8.GeoHash

  • Use the database to count people nearby
  • GeoHash algorithm
  • The basic use of Redis Geo instructions

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

9.Scan

  • Basic use of scan
  • The structure of the dictionary
  • scan traversal order
  • Dictionary expansion
  • Compare the traversal sequence before and after expansion and contraction
  • Progressive rehash
  • More scan instructions
  • Big key scan

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

If you need the help of a small partner who needs the PDF version of Redis Deep Notes, you can get it for free by adding a small assistant VX (gyhycx7980) as shown in the picture below!

PART3: Principles of Redis

1. Thread IO model

  • Non-blocking IO
  • Event polling (multiplexed)
  • Instruction queue
  • Response queue
  • Timed task

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

2. Communication protocol

  • RESP(Redis Serialization Protocol)
  • Client -> Server
  • Server -> Client

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

3. Endurance

  • Snapshot principle
  • fork (multi-process)
  • AOF principle
  • AOF rewrite
  • fsync
  • Operation and maintenance
  • Redis4.0 hybrid persistence

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

4. Pipeline

  • Redis message interaction
  • Pipeline pressure test
  • Deeply understand the nature of pipelines

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

è¾è®¯äºå¤§ç ¥ 亲ç âredisæ · ± 度ç¬è® ° âï¼ä¸è®²ä¸å ¥ åºè¯ï¼å¨æ¯ç²¾å

5. Affairs

  • Basic use of Redis transactions
  • Atomicity
  • discard
  • optimization
  • Watch

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

6.PubSub

  • Message multicast
  • PubSub
  • Mode subscription
  • Message structure
  • Disadvantages of PubSub

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

7. Small object compression

  • 32bit vs 64bit
  • Compressed storage of small objects (ziplist)
  • Memory reclamation mechanism
  • Memory allocation algorithm

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

8. Master-slave synchronization

  • CAP principle
  • Eventually unanimous
  • Master-slave synchronization
  • Incremental synchronization
  • Snapshot synchronization
  • Add slave node
  • Diskless copy
  • Wait instruction

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

If you need the help of a small partner who needs the PDF version of Redis Deep Notes, you can get it for free by adding a small assistant VX (gyhycx7980) as shown in the picture below!

PART4: Redis cluster

1.Sentinel

  • Message is lost
  • Sentinel basic use

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

2.Codes

  • Codis fragmentation principle
  • How to synchronize the slot relationship between different Codis instances?
  • Expansion
  • Automatic equalization
  • The price of Codis
  • Advantages of Codis
  • Operation process of MGET instruction
  • Architecture changes
  • Codis's embarrassment
  • Codis background management

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

3.Cluster

  • Slot location algorithm
  • Jump
  • migrate
  • Fault tolerance
  • Network jitter
  • Possibly offline (PFAIL-Possibly Fail) and confirmed offline (Fail)
  • Basic use of Cluster
  • Slot migration awareness
  • Cluster change awareness

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

If you need the help of a small partner who needs the PDF version of Redis Deep Notes, you can get it for free by adding a small assistant VX (gyhycx7980) as shown in the picture below!

PART5: Redis expansion

1.Stream

  • Message ID
  • Message content
  • Additions, deletions, modifications
  • Independent consumption
  • Create consumer group
  • consumption
  • What if there are too many Stream messages?
  • What happens if the message forgets the ACK?
  • How does PEL avoid message loss?
  • Stream's high availability
  • Partition

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

2.Info instruction

  • How many instructions does Redis execute per second?
  • How many clients are connected to Redis?
  • How much memory does Redisn take up?
  • How big is the copy backlog buffer area?

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

3. Talk about distributed locks again

  • Redlock algorithm
  • Redlock usage scenarios

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

4. Expiration strategy

  • Expired key collection
  • Timed scanning strategy
  • Expiration policy from library

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

5.LRU

  • LRU algorithm
  • Approximate LRU algorithm

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

6. Lazy delete

  • Why does Redis need to be lazy free?
  • flush
  • Asynchronous queue
  • AOF Sync is also very slow
  • More asynchronous delete points

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

7. Use Jedis gracefully

  • Retry

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

8. Protect Redis

  • Command security
  • Port security
  • Lua script security
  • SSL proxy

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

9. Redis secure communication

  • spiped principle
  • Getting started with spiped

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

If you need the help of a small partner who needs the PDF version of Redis Deep Notes, you can get it for free by adding a small assistant VX (gyhycx7980) as shown in the picture below!

PART6: Source code

1. Explore the internal structure of strings

  • embstr vs raw
  • Expansion strategy

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

2. Explore the interior of the dictionary

  • dict internal structure
  • Progressive rehash
  • Find process
  • hash function
  • hash attack
  • Expansion conditions
  • Shrinkage condition
  • structure of set

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

3. Explore the inside of the compressed list

  • Add elements
  • Cascade update
  • IntSet small integer set

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

4. Explore the inside of the quick list

  • How many elements are stored in each ziplist?
  • Compression depth

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

5. Explore the internal structure of the jump list

  • basic structure
  • Find process
  • Random layers
  • Insertion process
  • Delete process
  • Update process
  • What if the score values ​​are the same?
  • How is the element ranking calculated?

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

6. Explore the inside of the compact list

  • Cascade update
  • Replace ziplist

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

7. Explore the inside of the radix tree

  • application
  • structure
  • Add and delete nodes

Tencent Cloud God’s code "redis depth notes", don’t say a word of nonsense, it’s all the essence

 

to sum up

Finally, what I want to say is that learning is not difficult, and it is perseverance, especially after we participate in work, it is even more difficult to continue to persevere in learning. But for programmers, learning is the foundation of a career. If you give up learning, it will be sooner or later to be eliminated by the market. Therefore, learning more new knowledge is a greater investment for yourself.

That's it, that's it.

If you need the help of a small partner who needs the PDF version of Redis Deep Notes, you can get it for free by adding a small assistant VX (gyhycx7980) as shown in the picture below!

Guess you like

Origin blog.csdn.net/GYHYCX/article/details/113866786