In order to achieve a non-blocking transaction that handles the same method as a KEYS * query, I have the following code:
private int scanArgsLimit = 100000;
public List<String> listKeys(String keyPattern) {
KeyScanCursor<String> scanCursor = null;
List<String> keys = new ArrayList<String>();
RedisFuture<KeyScanCursor<String>> future = null;
do {
if (scanCursor == null) {
future = asyncRedisConnection.scan(ScanArgs.Builder.matches(keyPattern).limit(scanArgsLimit));
} else {
future = asyncRedisConnection.scan(scanCursor, ScanArgs.Builder.matches(keyPattern).limit(scanArgsLimit));
}
try {
scanCursor = future.get();
} catch (Exception e) {
return null;
}
keys.addAll(scanCursor.getKeys());
} while (!scanCursor.isFinished());
if (keys != null) {
keys.sort(String::compareTo);
}
return keys;
}
However, I've found that on larger key sets this does not appear to return all available keys. Is scanCursor.isFinished() called when 0 matching keys are returned from a cursor? If so, how do I scan the entire key space? (these are relatively small spaces, < 200k keys)