redis interview question 2

How does redis handle expired elements

Common Expiration Strategies

Scheduled deletion: set a scheduled deletion event for each key value. For example, if a key value expires at 5:00 today, then set an event to execute at 5:00 o’clock and delete its data (advantage: it can be cleared in time by using the memory invalid data

Disadvantage: It will waste a lot of redis resources, because when the amount of data is large, redis is running business, but here is deleting, redis itself is single-threaded, so it will have a great impact on redis performance )

Lazy deletion: When the user accesses the key value, it will verify whether the key value has expired, delete it if it expires, and return directly if it is not expired (advantage: it will not If it is triggered, it will always occupy memory)

Periodic deletion: it is some work to be deleted regularly to ensure that redis can run efficiently and delete invalid information (as shown below)

Redis uses the strategy of lazy deletion + regular deletion to delete

How does redis query a key in massive data

use scan

How does redis query nearby people

How to operate location information in redis: use redis3.2 geo type

The underlying implementation structure: zset ordered collection

The redis version is greater than 3.2 and you need to exclude yourself from the query when querying

Guess you like

Origin blog.csdn.net/bubbleJessica/article/details/132600816