Module lettuce.core

Class ScanIterator<T>

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 Details

    • scan

      public static <K,​ V> ScanIterator<K> scan​(RedisKeyCommands<K,​V> commands)
      Sequentially iterate over keys in the keyspace. This method uses SCAN to perform an iterative scan.
      Type Parameters:
      K - Key type.
      V - Value type.
      Parameters:
      commands - the commands interface, must not be null.
      Returns:
      a new ScanIterator.
    • scan

      public static <K,​ V> ScanIterator<K> scan​(RedisKeyCommands<K,​V> commands, ScanArgs scanArgs)
      Sequentially iterate over keys in the keyspace. This method uses SCAN to perform an iterative scan.
      Type Parameters:
      K - Key type.
      V - Value type.
      Parameters:
      commands - the commands interface, must not be null.
      scanArgs - the scan arguments, must not be null.
      Returns:
      a new ScanIterator.
    • hscan

      public static <K,​ V> ScanIterator<KeyValue<K,​V>> hscan​(RedisHashCommands<K,​V> commands, K key)
      Sequentially iterate over entries in a hash identified by key. This method uses HSCAN to perform an iterative scan.
      Type Parameters:
      K - Key type.
      V - Value type.
      Parameters:
      commands - the commands interface, must not be null.
      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 by key. This method uses HSCAN to perform an iterative scan.
      Type Parameters:
      K - Key type.
      V - Value type.
      Parameters:
      commands - the commands interface, must not be null.
      key - the hash to scan.
      scanArgs - the scan arguments, must not be null.
      Returns:
      a new ScanIterator.
    • sscan

      public static <K,​ V> ScanIterator<V> sscan​(RedisSetCommands<K,​V> commands, K key)
      Sequentially iterate over elements in a set identified by key. This method uses SSCAN to perform an iterative scan.
      Type Parameters:
      K - Key type.
      V - Value type.
      Parameters:
      commands - the commands interface, must not be null.
      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 by key. This method uses SSCAN to perform an iterative scan.
      Type Parameters:
      K - Key type.
      V - Value type.
      Parameters:
      commands - the commands interface, must not be null.
      key - the set to scan.
      scanArgs - the scan arguments, must not be null.
      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 by key. This method uses ZSCAN to perform an iterative scan.
      Type Parameters:
      K - Key type.
      V - Value type.
      Parameters:
      commands - the commands interface, must not be null.
      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 by key. This method uses ZSCAN to perform an iterative scan.
      Type Parameters:
      K - Key type.
      V - Value type.
      Parameters:
      commands - the commands interface, must not be null.
      key - the sorted set to scan.
      scanArgs - the scan arguments, must not be null.
      Returns:
      a new ScanIterator.
    • stream

      public Stream<T> stream()
      Returns a sequential Stream with this ScanIterator as its source.
      Returns:
      a Stream for this ScanIterator.