java.lang.Object
io.lettuce.core.ScanIterator<T>
- Type Parameters:
T- Element type
- All Implemented Interfaces:
Iterator<T>
public abstract class ScanIterator<T> extends Object implements Iterator<T>
Scan command support exposed through
Iterator.
ScanIterator uses synchronous command interfaces to scan over keys (SCAN), sets (SSCAN), sorted sets
(ZSCAN), and hashes (HSCAN). A ScanIterator is stateful and not thread-safe. Instances can be used
only once to iterate over results.
Use 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 ScanIterator.
- Since:
- 4.4
- Author:
- Mark Paluch
-
Method Summary
Modifier and Type Method Description static <K, V> ScanIterator<KeyValue<K,V>>hscan(RedisHashCommands<K,V> commands, K key)Sequentially iterate over entries in a hash identified bykey.static <K, V> ScanIterator<KeyValue<K,V>>hscan(RedisHashCommands<K,V> commands, K key, ScanArgs scanArgs)Sequentially iterate over entries in a hash identified bykey.static <K, V> ScanIterator<K>scan(RedisKeyCommands<K,V> commands)Sequentially iterate over keys in the keyspace.static <K, V> ScanIterator<K>scan(RedisKeyCommands<K,V> commands, ScanArgs scanArgs)Sequentially iterate over keys in the keyspace.static <K, V> ScanIterator<V>sscan(RedisSetCommands<K,V> commands, K key)Sequentially iterate over elements in a set identified bykey.static <K, V> ScanIterator<V>sscan(RedisSetCommands<K,V> commands, K key, ScanArgs scanArgs)Sequentially iterate over elements in a set identified bykey.Stream<T>stream()Returns a sequentialStreamwith thisScanIteratoras its source.static <K, V> ScanIterator<ScoredValue<V>>zscan(RedisSortedSetCommands<K,V> commands, K key)Sequentially iterate over scored values in a sorted set identified bykey.static <K, V> ScanIterator<ScoredValue<V>>zscan(RedisSortedSetCommands<K,V> commands, K key, ScanArgs scanArgs)Sequentially iterate over scored values in a sorted set identified bykey.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
scan
Sequentially iterate over keys in the keyspace. This method usesSCANto perform an iterative scan.- Type Parameters:
K- Key type.V- Value type.- Parameters:
commands- the commands interface, must not benull.- Returns:
- a new
ScanIterator.
-
scan
Sequentially iterate over keys in the keyspace. This method usesSCANto perform an iterative scan.- Type Parameters:
K- Key type.V- Value type.- Parameters:
commands- the commands interface, must not benull.scanArgs- the scan arguments, must not benull.- Returns:
- a new
ScanIterator.
-
hscan
Sequentially iterate over entries in a hash identified bykey. This method usesHSCANto perform an iterative scan.- Type Parameters:
K- Key type.V- Value type.- Parameters:
commands- the commands interface, must not benull.key- the hash to scan.- Returns:
- a new
ScanIterator.
-
hscan
public static <K, V> ScanIterator<KeyValue<K,V>> hscan(RedisHashCommands<K,V> commands, K key, ScanArgs scanArgs)Sequentially iterate over entries in a hash identified bykey. This method usesHSCANto perform an iterative scan.- Type Parameters:
K- Key type.V- Value type.- Parameters:
commands- the commands interface, must not benull.key- the hash to scan.scanArgs- the scan arguments, must not benull.- Returns:
- a new
ScanIterator.
-
sscan
Sequentially iterate over elements in a set identified bykey. This method usesSSCANto perform an iterative scan.- Type Parameters:
K- Key type.V- Value type.- Parameters:
commands- the commands interface, must not benull.key- the set to scan.- Returns:
- a new
ScanIterator.
-
sscan
public static <K, V> ScanIterator<V> sscan(RedisSetCommands<K,V> commands, K key, ScanArgs scanArgs)Sequentially iterate over elements in a set identified bykey. This method usesSSCANto perform an iterative scan.- Type Parameters:
K- Key type.V- Value type.- Parameters:
commands- the commands interface, must not benull.key- the set to scan.scanArgs- the scan arguments, must not benull.- Returns:
- a new
ScanIterator.
-
zscan
public static <K, V> ScanIterator<ScoredValue<V>> zscan(RedisSortedSetCommands<K,V> commands, K key)Sequentially iterate over scored values in a sorted set identified bykey. This method usesZSCANto perform an iterative scan.- Type Parameters:
K- Key type.V- Value type.- Parameters:
commands- the commands interface, must not benull.key- the sorted set to scan.- Returns:
- a new
ScanIterator.
-
zscan
public static <K, V> ScanIterator<ScoredValue<V>> zscan(RedisSortedSetCommands<K,V> commands, K key, ScanArgs scanArgs)Sequentially iterate over scored values in a sorted set identified bykey. This method usesZSCANto perform an iterative scan.- Type Parameters:
K- Key type.V- Value type.- Parameters:
commands- the commands interface, must not benull.key- the sorted set to scan.scanArgs- the scan arguments, must not benull.- Returns:
- a new
ScanIterator.
-
stream
Returns a sequentialStreamwith thisScanIteratoras its source.- Returns:
- a
Streamfor thisScanIterator.
-