-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
Description
I have just two properties:
A = anything
AA = anything
Result:
cursor 0
cursor 1
cursor 3
AbortError: SCAN can't be processed. The connection is already closed.
function scanAsync( redis, cursor, pattern, set ) {
return new Promise( ( resolve, reject ) => {
scan( redis, cursor, pattern, set, resolve, reject );
} );
}
function scan( redis, cursor, pattern, set, resolve, reject ) {
console.log( "cursor", cursor );
// Same result if using redis.scan( cursor, 'MATCH', pattern, 'COUNT', '1', function( err, res ) {
redis.send_command( 'scan', [ cursor, 'MATCH', pattern, 'COUNT', '1' ], function( err, res ) {
if ( err ) {
throw err;
}
// Update the cursor position for the next scan
cursor = res[ 0 ];
// get the SCAN result for this iteration
var keys = res[ 1 ];
// Result is more or less than COUNT, or no keys may be returned.
// SCAN may return the same key multiple times.
if ( keys.length > 0 ) {
keys.forEach( function( key, i ) {
set.add( key );
} );
}
// An iteration starts when the cursor is set to 0
// and terminates when the cursor returned by the server is 0.
if ( cursor === '0' ) {
resolve( true );
}
else {
scan( redis, cursor, pattern, set, resolve, reject );
}
} );
}
var myResults = new Set();
var redis = require( "redis" );
scanAsync( this.redis, '0', "A*", myResults ).then( function( value ) {
console.log( value, "myResults", myResults, Array.from( myResults ) );
}, function( err ) {
console.log( err );
} );
The server works ok:
mine:0>scan 0 'A*' 1
"ERR syntax error"
mine:0>scan 0 MATCH A* COUNT 1
- "1"
-
- "AA"
mine:0>scan 1 MATCH A* COUNT 1
- "3"
-
- "A"
mine:0>scan 3 MATCH A* COUNT 1
- "0"