Interface StreamOperations<K,HK,HV>

All Superinterfaces:
HashMapperProvider<HK,HV>

public interface StreamOperations<K,HK,HV> extends HashMapperProvider<HK,HV>
Redis stream specific operations.
Since:
2.2
Author:
Mark Paluch, Christoph Strobl, Dengliming, Marcin Zielinski, John Blum
  • Method Details

    • acknowledge

      @Nullable Long acknowledge(K key, String group, String... recordIds)
      Acknowledge one or more records as processed.
      Parameters:
      key - the stream key.
      group - name of the consumer group.
      recordIds - record id's to acknowledge.
      Returns:
      length of acknowledged records. null when used in pipeline / transaction.
      See Also:
    • acknowledge

      @Nullable default Long acknowledge(K key, String group, RecordId... recordIds)
      Acknowledge one or more records as processed.
      Parameters:
      key - the stream key.
      group - name of the consumer group.
      recordIds - record id's to acknowledge.
      Returns:
      length of acknowledged records. null when used in pipeline / transaction.
      See Also:
    • acknowledge

      default Long acknowledge(String group, Record<K,?> record)
      Acknowledge the given record as processed.
      Parameters:
      group - name of the consumer group.
      record - the Record to acknowledge.
      Returns:
      length of acknowledged records. null when used in pipeline / transaction.
      See Also:
    • add

      @Nullable default RecordId add(K key, Map<? extends HK,? extends HV> content)
      Append a record to the stream key.
      Parameters:
      key - the stream key.
      content - record content as Map.
      Returns:
      the record Id. null when used in pipeline / transaction.
      See Also:
    • add

      @Nullable default RecordId add(MapRecord<K,? extends HK,? extends HV> record)
      Append a record, backed by a Map holding the field/value pairs, to the stream.
      Parameters:
      record - the record to append.
      Returns:
      the record Id. null when used in pipeline / transaction.
      See Also:
    • add

      @Nullable RecordId add(Record<K,?> record)
      Append the record, backed by the given value, to the stream. The value is mapped as hash and serialized.
      Parameters:
      record - must not be null.
      Returns:
      the record Id. null when used in pipeline / transaction.
      See Also:
    • claim

      default List<MapRecord<K,HK,HV>> claim(K key, String consumerGroup, String newOwner, Duration minIdleTime, RecordId... recordIds)
      Changes the ownership of a pending message so that the new owner is the consumer specified as the command argument. The message is claimed only if its idle time (ms) is greater than the given minimum idle time specified when calling XCLAIM.
      Parameters:
      key - key to the steam.
      consumerGroup - name of the consumer group.
      newOwner - name of the consumer claiming the message.
      minIdleTime - minimum idle time required for a message to be claimed.
      recordIds - record IDs to be claimed.
      Returns:
      List of claimed MapRecords.
      See Also:
    • claim

      List<MapRecord<K,HK,HV>> claim(K key, String consumerGroup, String newOwner, RedisStreamCommands.XClaimOptions xClaimOptions)
      Changes the ownership of a pending message so that the new owner is the consumer specified as the command argument. The message is claimed only if its idle time (ms) is greater than the given minimum idle time specified when calling XCLAIM.
      Parameters:
      key - key to the steam.
      consumerGroup - name of the consumer group.
      newOwner - name of the consumer claiming the message.
      xClaimOptions - additional parameters for the CLAIM call.
      Returns:
      List of claimed MapRecords.
      See Also:
    • delete

      @Nullable default Long delete(K key, String... recordIds)
      Removes the specified records from the stream. Returns the number of records deleted, that may be different from the number of IDs passed in case certain IDs do not exist.
      Parameters:
      key - the stream key.
      recordIds - stream record Id's.
      Returns:
      number of removed entries. null when used in pipeline / transaction.
      See Also:
    • delete

      @Nullable default Long delete(Record<K,?> record)
      Removes a given Record from the stream.
      Parameters:
      record - must not be null.
      Returns:
      he Mono emitting the number of removed records.
    • delete

      @Nullable Long delete(K key, RecordId... recordIds)
      Removes the specified records from the stream. Returns the number of records deleted, that may be different from the number of IDs passed in case certain IDs do not exist.
      Parameters:
      key - the stream key.
      recordIds - stream record Id's.
      Returns:
      the Mono emitting the number of removed records.
      See Also:
    • createGroup

      default String createGroup(K key, String group)
      Create a consumer group at the latest offset. This command creates the stream if it does not already exist.
      Parameters:
      key - the key the stream is stored at.
      group - name of the consumer group.
      Returns:
      OK if successful. null when used in pipeline / transaction.
    • createGroup

      @Nullable String createGroup(K key, ReadOffset readOffset, String group)
      Create a consumer group. This command creates the stream if it does not already exist.
      Parameters:
      key - the key the stream is stored at.
      readOffset - the ReadOffset to apply.
      group - name of the consumer group.
      Returns:
      OK if successful. null when used in pipeline / transaction.
    • deleteConsumer

      @Nullable Boolean deleteConsumer(K key, Consumer consumer)
      Delete a consumer from a consumer group.
      Parameters:
      key - the stream key.
      consumer - consumer identified by group name and consumer key.
      Returns:
      true if successful. null when used in pipeline / transaction.
    • destroyGroup

      @Nullable Boolean destroyGroup(K key, String group)
      Destroy a consumer group.
      Parameters:
      key - the stream key.
      group - name of the consumer group.
      Returns:
      true if successful. null when used in pipeline / transaction.
    • consumers

      StreamInfo.XInfoConsumers consumers(K key, String group)
      Obtain information about every consumer in a specific consumer group for the stream stored at the specified key.
      Parameters:
      key - the key the stream is stored at.
      group - name of the consumer group.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.3
    • groups

      Obtain information about consumer groups associated with the stream stored at the specified key.
      Parameters:
      key - the key the stream is stored at.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.3
    • info

      Obtain general information about the stream stored at the specified key.
      Parameters:
      key - the key the stream is stored at.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.3
    • pending

      @Nullable PendingMessagesSummary pending(K key, String group)
      Obtain the PendingMessagesSummary for a given consumer group.
      Parameters:
      key - the key the stream is stored at. Must not be null.
      group - the name of the consumer group. Must not be null.
      Returns:
      a summary of pending messages within the given consumer group or null when used in pipeline / transaction.
      Since:
      2.3
      See Also:
    • pending

      default PendingMessages pending(K key, Consumer consumer)
      Obtained detailed information about all pending messages for a given Consumer.
      Parameters:
      key - the key the stream is stored at. Must not be null.
      consumer - the consumer to fetch PendingMessages for. Must not be null.
      Returns:
      pending messages for the given Consumer or null when used in pipeline / transaction.
      Since:
      2.3
      See Also:
    • pending

      PendingMessages pending(K key, String group, Range<?> range, long count)
      Obtain detailed information about pending messages for a given Range within a consumer group.
      Parameters:
      key - the key the stream is stored at. Must not be null.
      group - the name of the consumer group. Must not be null.
      range - the range of messages ids to search within. Must not be null.
      count - limit the number of results.
      Returns:
      pending messages for the given consumer group or null when used in pipeline / transaction.
      Since:
      2.3
      See Also:
    • pending

      PendingMessages pending(K key, Consumer consumer, Range<?> range, long count)
      Obtain detailed information about pending messages for a given Range and Consumer within a consumer group.
      Parameters:
      key - the key the stream is stored at. Must not be null.
      consumer - the name of the Consumer. Must not be null.
      range - the range of messages ids to search within. Must not be null.
      count - limit the number of results.
      Returns:
      pending messages for the given Consumer or null when used in pipeline / transaction.
      Since:
      2.3
      See Also:
    • size

      @Nullable Long size(K key)
      Get the length of a stream.
      Parameters:
      key - the stream key.
      Returns:
      length of the stream. null when used in pipeline / transaction.
      See Also:
    • range

      @Nullable default List<MapRecord<K,HK,HV>> range(K key, Range<String> range)
      Read records from a stream within a specific Range.
      Parameters:
      key - the stream key.
      range - must not be null.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • range

      @Nullable List<MapRecord<K,HK,HV>> range(K key, Range<String> range, Limit limit)
      Read records from a stream within a specific Range applying a Limit.
      Parameters:
      key - the stream key.
      range - must not be null.
      limit - must not be null.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • range

      default <V> List<ObjectRecord<K,V>> range(Class<V> targetType, K key, Range<String> range)
      Read all records from a stream within a specific Range as ObjectRecord.
      Parameters:
      targetType - the target type of the payload.
      key - the stream key.
      range - must not be null.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • range

      default <V> List<ObjectRecord<K,V>> range(Class<V> targetType, K key, Range<String> range, Limit limit)
      Read records from a stream within a specific Range applying a Limit as ObjectRecord.
      Parameters:
      targetType - the target type of the payload.
      key - the stream key.
      range - must not be null.
      limit - must not be null.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • read

      @Nullable default List<MapRecord<K,HK,HV>> read(StreamOffset<K>... streams)
      Read records from one or more StreamOffsets.
      Parameters:
      streams - the streams to read from.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • read

      default <V> List<ObjectRecord<K,V>> read(Class<V> targetType, StreamOffset<K>... streams)
      Read records from one or more StreamOffsets as ObjectRecord.
      Parameters:
      targetType - the target type of the payload.
      streams - the streams to read from.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • read

      @Nullable List<MapRecord<K,HK,HV>> read(StreamReadOptions readOptions, StreamOffset<K>... streams)
      Read records from one or more StreamOffsets.
      Parameters:
      readOptions - read arguments.
      streams - the streams to read from.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • read

      @Nullable default <V> List<ObjectRecord<K,V>> read(Class<V> targetType, StreamReadOptions readOptions, StreamOffset<K>... streams)
      Read records from one or more StreamOffsets as ObjectRecord.
      Parameters:
      targetType - the target type of the payload.
      readOptions - read arguments.
      streams - the streams to read from.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • read

      @Nullable default List<MapRecord<K,HK,HV>> read(Consumer consumer, StreamOffset<K>... streams)
      Read records from one or more StreamOffsets using a consumer group.
      Parameters:
      consumer - consumer/group.
      streams - the streams to read from.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • read

      @Nullable default <V> List<ObjectRecord<K,V>> read(Class<V> targetType, Consumer consumer, StreamOffset<K>... streams)
      Read records from one or more StreamOffsets using a consumer group as ObjectRecord.
      Parameters:
      targetType - the target type of the payload.
      consumer - consumer/group.
      streams - the streams to read from.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • read

      @Nullable List<MapRecord<K,HK,HV>> read(Consumer consumer, StreamReadOptions readOptions, StreamOffset<K>... streams)
      Read records from one or more StreamOffsets using a consumer group.
      Parameters:
      consumer - consumer/group.
      readOptions - read arguments.
      streams - the streams to read from.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • read

      @Nullable default <V> List<ObjectRecord<K,V>> read(Class<V> targetType, Consumer consumer, StreamReadOptions readOptions, StreamOffset<K>... streams)
      Read records from one or more StreamOffsets using a consumer group as ObjectRecord.
      Parameters:
      targetType - the target type of the payload.
      consumer - consumer/group.
      readOptions - read arguments.
      streams - the streams to read from.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • reverseRange

      @Nullable default List<MapRecord<K,HK,HV>> reverseRange(K key, Range<String> range)
      Read records from a stream within a specific Range in reverse order.
      Parameters:
      key - the stream key.
      range - must not be null.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • reverseRange

      @Nullable List<MapRecord<K,HK,HV>> reverseRange(K key, Range<String> range, Limit limit)
      Read records from a stream within a specific Range applying a Limit in reverse order.
      Parameters:
      key - the stream key.
      range - must not be null.
      limit - must not be null.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • reverseRange

      default <V> List<ObjectRecord<K,V>> reverseRange(Class<V> targetType, K key, Range<String> range)
      Read records from a stream within a specific Range in reverse order as ObjectRecord.
      Parameters:
      targetType - the target type of the payload.
      key - the stream key.
      range - must not be null.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • reverseRange

      default <V> List<ObjectRecord<K,V>> reverseRange(Class<V> targetType, K key, Range<String> range, Limit limit)
      Read records from a stream within a specific Range applying a Limit in reverse order as ObjectRecord.
      Parameters:
      targetType - the target type of the payload.
      key - the stream key.
      range - must not be null.
      limit - must not be null.
      Returns:
      list with members of the resulting stream. null when used in pipeline / transaction.
      See Also:
    • trim

      @Nullable Long trim(K key, long count)
      Trims the stream to count elements.
      Parameters:
      key - the stream key.
      count - length of the stream.
      Returns:
      number of removed entries. null when used in pipeline / transaction.
      See Also:
    • trim

      @Nullable Long trim(K key, long count, boolean approximateTrimming)
      Trims the stream to count elements.
      Parameters:
      key - the stream key.
      count - length of the stream.
      approximateTrimming - the trimming must be performed in a approximated way in order to maximize performances.
      Returns:
      number of removed entries. null when used in pipeline / transaction.
      Since:
      2.4
      See Also:
    • getHashMapper

      <V> HashMapper<V,HK,HV> getHashMapper(Class<V> targetType)
      Get the HashMapper for a specific type.
      Specified by:
      getHashMapper in interface HashMapperProvider<K,HK>
      Type Parameters:
      V -
      Parameters:
      targetType - must not be null.
      Returns:
      the HashMapper suitable for a given type;
    • map

      default <V> ObjectRecord<K,V> map(MapRecord<K,HK,HV> record, Class<V> targetType)
      Map record from MapRecord to ObjectRecord.
      Parameters:
      record - the stream record to map.
      targetType - the target type of the payload.
      Returns:
      the mapped ObjectRecord.
      Since:
      2.x
    • map

      @Nullable default <V> List<ObjectRecord<K,V>> map(@Nullable List<MapRecord<K,HK,HV>> records, Class<V> targetType)
      Map records from MapRecord to ObjectRecords.
      Parameters:
      records - the stream records to map.
      targetType - the target type of the payload.
      Returns:
      the mapped object records.
      Since:
      2.x
    • deserializeRecord

      MapRecord<K,HK,HV> deserializeRecord(ByteRecord record)
      Deserialize a ByteRecord using the configured serializers into a MapRecord.
      Parameters:
      record - the stream record to map.
      Returns:
      deserialized MapRecord.
      Since:
      2.x