Skip to content

Commit ff020d3

Browse files
author
Jeremiah Lee Cohick
committed
Clarified COUNT's behavior. scan() now will run until cursor reaches 0.
1 parent 6f28c6a commit ff020d3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

examples/scan.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ function scan() {
1515
cursor = res[0];
1616

1717
// From <http://redis.io/commands/scan>:
18-
// An iteration starts when the cursor is set to 0,
19-
// and terminates when the cursor returned by the server is 0.
18+
// "An iteration starts when the cursor is set to 0,
19+
// and terminates when the cursor returned by the server is 0."
2020
if (cursor === '0') {
2121
return console.log('Iteration complete');
2222
} else {
23-
// Remember, more keys than COUNT or no keys may be returned
23+
// Remember: more or less than COUNT or no keys may be returned
2424
// See http://redis.io/commands/scan#the-count-option
25+
// Also, SCAN may return the same key multiple times
26+
// See http://redis.io/commands/scan#scan-guarantees
27+
2528
if (res[1].length > 0) {
26-
return console.log('Array of matching keys', res[1]);
27-
} else {
28-
// No keys were returned in this scan, but more keys exist.
29-
return scan();
29+
console.log('Array of matching keys', res[1]);
3030
}
31+
32+
return scan();
3133
}
3234
}
3335
);

0 commit comments

Comments
 (0)