File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ var redis = require ( "redis" ) ,
2+ client = redis . createClient ( ) ;
3+
4+ var cursor = '0' ;
5+
6+ function scan ( ) {
7+ client . scan (
8+ cursor ,
9+ "MATCH" , "q:job:*" ,
10+ "COUNT" , "10" ,
11+ function ( err , res ) {
12+ if ( err ) throw err ;
13+
14+ // Update the cursor position for the next scan
15+ cursor = res [ 0 ] ;
16+
17+ // 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."
20+ if ( cursor === '0' ) {
21+ return console . log ( 'Iteration complete' ) ;
22+ } else {
23+ // Remember: more or less than COUNT or no keys may be returned
24+ // 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+
28+ if ( res [ 1 ] . length > 0 ) {
29+ console . log ( 'Array of matching keys' , res [ 1 ] ) ;
30+ }
31+
32+ return scan ( ) ;
33+ }
34+ }
35+ ) ;
36+ }
You can’t perform that action at this time.
0 commit comments