diff --git a/src/main/java/io/lettuce/core/ScanIterator.java b/src/main/java/io/lettuce/core/ScanIterator.java
index 3dfd362f23..825625bd71 100644
--- a/src/main/java/io/lettuce/core/ScanIterator.java
+++ b/src/main/java/io/lettuce/core/ScanIterator.java
@@ -34,6 +34,12 @@
* {@link ScanIterator} uses synchronous command interfaces to scan over keys ({@code SCAN}), sets ({@code SSCAN}), sorted sets
* ({@code ZSCAN}), and hashes ({@code HSCAN}). A {@link ScanIterator} is stateful and not thread-safe. Instances can be used
* only once to iterate over results.
+ *
+ * Use {@link ScanArgs#limit(long)} to set the batch size.
+ *
+ * Data structure scanning is progressive and stateful and demand-aware. It supports full iterations (until all received cursors
+ * are exhausted) and premature termination. Subsequent scan commands to fetch the cursor data get only issued if the caller
+ * signals demand by consuming the {@link ScanIterator}.
*
* @param Element type
* @author Mark Paluch
@@ -41,6 +47,9 @@
*/
public abstract class ScanIterator implements Iterator {
+ private ScanIterator() {
+ }
+
/**
* Sequentially iterate over keys in the keyspace. This method uses {@code SCAN} to perform an iterative scan.
*
@@ -89,8 +98,8 @@ private KeyScanCursor getNextScanCursor(ScanCursor scanCursor) {
return scanArgs.map(commands::scan).orElseGet(commands::scan);
}
- return scanArgs.map((scanArgs) -> commands.scan(scanCursor, scanArgs))
- .orElseGet(() -> commands.scan(scanCursor));
+ return scanArgs.map((scanArgs) -> commands.scan(scanCursor, scanArgs)).orElseGet(
+ () -> commands.scan(scanCursor));
}
};
}
@@ -100,6 +109,7 @@ private KeyScanCursor getNextScanCursor(ScanCursor scanCursor) {
* iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
+ * @param key the hash to scan.
* @param Key type.
* @param Value type.
* @return a new {@link ScanIterator}.
@@ -113,6 +123,7 @@ public static ScanIterator> hscan(RedisHashCommands
* iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
+ * @param key the hash to scan.
* @param scanArgs the scan arguments, must not be {@literal null}.
* @param Key type.
* @param Value type.
@@ -147,8 +158,8 @@ private MapScanCursor getNextScanCursor(ScanCursor scanCursor) {
return scanArgs.map(scanArgs -> commands.hscan(key, scanArgs)).orElseGet(() -> commands.hscan(key));
}
- return scanArgs.map((scanArgs) -> commands.hscan(key, scanCursor, scanArgs))
- .orElseGet(() -> commands.hscan(key, scanCursor));
+ return scanArgs.map((scanArgs) -> commands.hscan(key, scanCursor, scanArgs)).orElseGet(
+ () -> commands.hscan(key, scanCursor));
}
};
}
@@ -158,6 +169,7 @@ private MapScanCursor getNextScanCursor(ScanCursor scanCursor) {
* iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
+ * @param key the set to scan.
* @param Key type.
* @param Value type.
* @return a new {@link ScanIterator}.
@@ -171,6 +183,7 @@ public static ScanIterator sscan(RedisSetCommands commands, K ke
* iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
+ * @param key the set to scan.
* @param scanArgs the scan arguments, must not be {@literal null}.
* @param Key type.
* @param Value type.
@@ -204,8 +217,8 @@ private ValueScanCursor getNextScanCursor(ScanCursor scanCursor) {
return scanArgs.map(scanArgs -> commands.sscan(key, scanArgs)).orElseGet(() -> commands.sscan(key));
}
- return scanArgs.map((scanArgs) -> commands.sscan(key, scanCursor, scanArgs))
- .orElseGet(() -> commands.sscan(key, scanCursor));
+ return scanArgs.map((scanArgs) -> commands.sscan(key, scanCursor, scanArgs)).orElseGet(
+ () -> commands.sscan(key, scanCursor));
}
};
}
@@ -215,6 +228,7 @@ private ValueScanCursor getNextScanCursor(ScanCursor scanCursor) {
* perform an iterative scan.
*
* @param commands the commands interface, must not be {@literal null}.
+ * @param key the sorted set to scan.
* @param Key type.
* @param Value type.
* @return a new {@link ScanIterator}.
@@ -228,6 +242,7 @@ public static ScanIterator> zscan(RedisSortedSetCommands Key type.
* @param Value type.
@@ -262,8 +277,8 @@ private ScoredValueScanCursor getNextScanCursor(ScanCursor scanCursor) {
return scanArgs.map(scanArgs -> commands.zscan(key, scanArgs)).orElseGet(() -> commands.zscan(key));
}
- return scanArgs.map((scanArgs) -> commands.zscan(key, scanCursor, scanArgs))
- .orElseGet(() -> commands.zscan(key, scanCursor));
+ return scanArgs.map((scanArgs) -> commands.zscan(key, scanCursor, scanArgs)).orElseGet(
+ () -> commands.zscan(key, scanCursor));
}
};
}