Skip to content

Commit

Permalink
Clarified COUNT's behavior. scan() now will run until cursor reaches 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremiah Lee Cohick committed Jul 11, 2015
1 parent 6f28c6a commit ff020d3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions examples/scan.js
Expand Up @@ -15,19 +15,21 @@ function scan() {
cursor = res[0];

// From <http://redis.io/commands/scan>:
// An iteration starts when the cursor is set to 0,
// and terminates when the cursor returned by the server is 0.
// "An iteration starts when the cursor is set to 0,
// and terminates when the cursor returned by the server is 0."
if (cursor === '0') {
return console.log('Iteration complete');
} else {
// Remember, more keys than COUNT or no keys may be returned
// Remember: more or less than COUNT or no keys may be returned
// See http://redis.io/commands/scan#the-count-option
// Also, SCAN may return the same key multiple times
// See http://redis.io/commands/scan#scan-guarantees

if (res[1].length > 0) {
return console.log('Array of matching keys', res[1]);
} else {
// No keys were returned in this scan, but more keys exist.
return scan();
console.log('Array of matching keys', res[1]);
}

return scan();
}
}
);
Expand Down

0 comments on commit ff020d3

Please sign in to comment.