From ff020d37f34ab503e9cfeac7490c6773eb3f93ee Mon Sep 17 00:00:00 2001 From: Jeremiah Lee Cohick Date: Fri, 10 Jul 2015 18:04:38 -0700 Subject: [PATCH] Clarified COUNT's behavior. scan() now will run until cursor reaches 0. --- examples/scan.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/scan.js b/examples/scan.js index 35238b6e835..0302843a768 100644 --- a/examples/scan.js +++ b/examples/scan.js @@ -15,19 +15,21 @@ function scan() { cursor = res[0]; // From : - // 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(); } } );