use of com.lambdaworks.redis.ScanCursor in project moleculer-java by moleculer-java.
the class RedisGetSetClient method clean.
private final CompletionStage<Object> clean(RedisFuture<KeyScanCursor<byte[]>> future, ScanArgs args, String match) {
return future.thenCompose(keyScanCursor -> {
List<byte[]> keys = keyScanCursor.getKeys();
if (keys == null || keys.isEmpty()) {
return CompletableFuture.completedFuture(keyScanCursor);
}
if (match != null) {
Iterator<byte[]> i = keys.iterator();
while (i.hasNext()) {
if (!Matcher.matches(new String(i.next(), StandardCharsets.UTF_8), match)) {
i.remove();
}
}
}
if (keys.isEmpty()) {
return CompletableFuture.completedFuture(keyScanCursor);
}
byte[][] array = new byte[keys.size()][];
keys.toArray(array);
return client.del(array).thenApply(nul -> keyScanCursor);
}).thenApply(keyScanCursor -> {
if (((KeyScanCursor<byte[]>) keyScanCursor).isFinished()) {
return null;
}
return ((KeyScanCursor<byte[]>) keyScanCursor).getCursor();
}).thenCompose(currentCursor -> {
if (currentCursor == null) {
return CompletableFuture.completedFuture(null);
}
return clean(new ScanCursor((String) currentCursor, false), args, match);
});
}
Aggregations