Lettuce Scan function returns Exception java.lang.IllegalArgumentException: A scan in Redis Cluster mode requires to reuse the resulting cursor from the previous scan invocation

33 views
Skip to first unread message

REHAN UBAID

unread,
Oct 14, 2020, 1:13:27 PM10/14/20
to lettuce-redis-client-users
Hi team,
I am running a code snippet

ScanArgs scanArgs = new ScanArgs().match("myKey:*").limit(1000);
KeyScanCursor<byte[]> keyScanCursor = RedisLettuceExecutor.executeRedis(redisDataSource,
redisAdvancedClusterCommands -> redisAdvancedClusterCommands.scan(scanArgs));
resultKeys.addAll(keyScanCursor.getKeys());
log.info("[lettuce] current cursor: {}", keyScanCursor.getCursor());
log.info("[lettuce] current cursor key size: {}", keyScanCursor.getKeys().size());
Thread.sleep(sleep);
while (!keyScanCursor.getCursor().equalsIgnoreCase("0")){
Thread.sleep(waitingTime);
numTimeFallAsSleep++;
keyScanCursor = scan(ScanCursor.of(keyScanCursor.getCursor()), scanArgs);
resultKeys.addAll(keyScanCursor.getKeys());
}

private KeyScanCursor<byte[]> scan(ScanCursor scanCursor, ScanArgs scanArgs) {
log.info("[Lettuce Tee4j] previous cursor: {}", scanCursor.getCursor());
KeyScanCursor<byte[]> keyScanCursor = RedisLettuceExecutor.executeRedis(redisDataSource, redisAdvancedClusterCommands -> redisAdvancedClusterCommands.scan(scanCursor, scanArgs));
log.info("[Lettuce] current cursor: {}", keyScanCursor.getCursor());
log.info("[Lettuce] current cursor keys size: {}", keyScanCursor.getKeys().size());
return keyScanCursor;
}

But the code runs only once, The Previous and current cursor value is same but i keep getting Exception "java.lang.IllegalArgumentException: A scan in Redis Cluster mode requires to reuse the resulting cursor from the previous scan invocation"

REHAN UBAID

unread,
Oct 14, 2020, 1:14:57 PM10/14/20
to lettuce-redis-client-users
I am reading from replica while doing the full scan.

Mark Paluch

unread,
Oct 15, 2020, 2:22:43 AM10/15/20
to lettuce-redis-client-users
The exception message explains how to fix the issue. Reuse keyScanCursor for the next scan. Alternatively, use ScanIterator for a simpler scanning code.
Reply all
Reply to author
Forward
0 new messages