A number of sources, including the official Redis documentation, note that using the KEYS
command is a bad idea in production environments due to possible blocking. If the approximate size of the dataset is known, does SCAN
have any advantage over KEYS
?
For example, consider a database with at most 100 keys of the form data:number:X
where X
is an integer. If I want to retrieve all of these, I might use the command KEYS data:number:*
. Is this going to be significantly slower than using SCAN 0 MATCH data:number:* COUNT 100
? Or are the two commands essentially equivalent in this circumstance? Would it be accurate to say that SCAN
is preferable to KEYS
because it protects against the scenario where an unexpectedly large set would be returned?