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