I've been trying to get a scan working using reactive commands and I can't quite wrap my head around it. In this example below, I simply want to scan the key and add the results to a list.
I understand how to do it in a non-reactive way using sync():
ScanArgs scanArgs = ScanArgs.Builder.matches(workName).limit(15);
KeyScanCursor<String> keyScanCursor = new KeyScanCursor<>();
keyScanCursor.setCursor(ScanCursor.INITIAL.getCursor());
List<String> someList = new ArrayList<>();
do {
keyScanCursor = redisConnection.sync().scan(keyScanCursor, scanArgs);
someList.addAll(keyScanCursor.getKeys());
} while (!keyScanCursor.isFinished());
But moving to a reactive way of doing it completely throws me off. If you're trying to call the keyScanCursor again in the mono, you'd just get another mono back.
Here's an example of the reactive key scan returning a mono. I've actually tried it a few different ways, so this is just one of the ways (and considering it's not iterating the keyScanCursor, it's not one I believe would work anyway).
ScanArgs scanArgs = ScanArgs.Builder.matches(workName).limit(15);
Mono<KeyScanCursor<String>> scanKeysMono = redisConnection.reactive().scan(scanArgs);
scanKeysMono.map(keyScanCursor -> {
someArrayList.addAll(keyScanCursor.getKeys());
LOG.debug("Found {} .", someArrayList.size());
return 0;
}).subscribe();