[One question per day] If there are 100 million keys in Redis, and 10w of them start with a fixed, known prefix, how to find them all?

Use the keys command to scan out the key list of the specified mode.
The other party then asked: If this redis is providing services to online businesses, what are the problems with using the keys command?
At this time, you have to answer a key feature of redis: redis's single-threaded. The keys instruction will cause the thread to block for a period of time, and the online service will be paused. The service cannot be restored until the instruction is executed. At this time, you can use the scan command. The scan command can extract the key list of the specified mode without blocking, but there will be a certain probability of repetition. It is enough to do a deduplication on the client side, but the overall time will be more than direct use The keys instruction is long.

Guess you like

Origin blog.csdn.net/Black_Customer/article/details/107944997