Interface RedisStreamCommands

All Known Subinterfaces:
DefaultedRedisClusterConnection, DefaultedRedisConnection, RedisClusterConnection, RedisCommands, RedisConnection, RedisConnectionUtils.RedisConnectionProxy, StringRedisConnection
All Known Implementing Classes:
AbstractRedisConnection, DefaultStringRedisConnection, JedisClusterConnection, JedisConnection, LettuceClusterConnection, LettuceConnection

public interface RedisStreamCommands
Stream-specific Redis commands.
Since:
2.2
Author:
Mark Paluch, Christoph Strobl, Tugdual Grall, Dengliming, Mark John Moreno
See Also:
  • Method Details

    • xAck

      @Nullable default Long xAck(byte[] key, String group, String... recordIds)
      Acknowledge one or more records, identified via their id, as processed.
      Parameters:
      key - the key the stream is stored at.
      group - name of the consumer group.
      recordIds - the String representation of the id's of the records to acknowledge.
      Returns:
      length of acknowledged messages. null when used in pipeline / transaction.
      See Also:
    • xAck

      @Nullable Long xAck(byte[] key, String group, RecordId... recordIds)
      Acknowledge one or more records, identified via their id, as processed.
      Parameters:
      key - the key the stream is stored at.
      group - name of the consumer group.
      recordIds - the id's of the records to acknowledge.
      Returns:
      length of acknowledged messages. null when used in pipeline / transaction.
      See Also:
    • xAdd

      @Nullable default RecordId xAdd(byte[] key, Map<byte[],byte[]> content)
      Append a new record with the given field/value pairs as content to the stream stored at key.
      Parameters:
      key - the key the stream is stored at.
      content - the records content modeled as field/value pairs.
      Returns:
      the server generated id. null when used in pipeline / transaction.
      See Also:
    • xAdd

      @Nullable default RecordId xAdd(MapRecord<byte[],byte[],byte[]> record)
      Append the given record to the stream stored at Record#getStream. If you prefer manual id assignment over server generated ones make sure to provide an id via Record#withId.
      Parameters:
      record - the record to append.
      Returns:
      the id after save. null when used in pipeline / transaction.
    • xAdd

      @Nullable RecordId xAdd(MapRecord<byte[],byte[],byte[]> record, RedisStreamCommands.XAddOptions options)
      Append the given record to the stream stored at Record#getStream. If you prefer manual id assignment over server generated ones make sure to provide an id via Record#withId.
      Parameters:
      record - the record to append.
      options - additional options (eg. MAXLEN). Must not be null, use RedisStreamCommands.XAddOptions.none() instead.
      Returns:
      the id after save. null when used in pipeline / transaction.
      Since:
      2.3
    • xClaimJustId

      @Nullable List<RecordId> xClaimJustId(byte[] key, String group, String newOwner, RedisStreamCommands.XClaimOptions options)
      Change the ownership of a pending message to the given new consumer without increasing the delivered count.
      Parameters:
      key - the key the stream is stored at.
      group - the name of the consumer group.
      newOwner - the name of the new consumer.
      options - must not be null.
      Returns:
      list of ids that changed user.
      Since:
      2.3
      See Also:
    • xClaim

      @Nullable default List<ByteRecord> xClaim(byte[] key, String group, String newOwner, Duration minIdleTime, RecordId... recordIds)
      Change the ownership of a pending message to the given new consumer.
      Parameters:
      key - the key the stream is stored at.
      group - the name of the consumer group.
      newOwner - the name of the new consumer.
      minIdleTime - must not be null.
      recordIds - must not be null.
      Returns:
      list of ByteRecord that changed user.
      Since:
      2.3
      See Also:
    • xClaim

      @Nullable List<ByteRecord> xClaim(byte[] key, String group, String newOwner, RedisStreamCommands.XClaimOptions options)
      Change the ownership of a pending message to the given new consumer.
      Parameters:
      key - the key the stream is stored at.
      group - the name of the consumer group.
      newOwner - the name of the new consumer.
      options - must not be null.
      Returns:
      list of ByteRecord that changed user.
      Since:
      2.3
      See Also:
    • xDel

      @Nullable default Long xDel(byte[] key, String... recordIds)
      Removes the records with the given id's from the stream. Returns the number of items deleted, that may be different from the number of id's passed in case certain id's do not exist.
      Parameters:
      key - the key the stream is stored at.
      recordIds - the id's of the records to remove.
      Returns:
      number of removed entries. null when used in pipeline / transaction.
      See Also:
    • xDel

      @Nullable Long xDel(byte[] key, RecordId... recordIds)
      Removes the records with the given id's from the stream. Returns the number of items deleted, that may be different from the number of id's passed in case certain id's do not exist.
      Parameters:
      key - the key the stream is stored at.
      recordIds - the id's of the records to remove.
      Returns:
      number of removed entries. null when used in pipeline / transaction.
      See Also:
    • xGroupCreate

      @Nullable String xGroupCreate(byte[] key, String groupName, ReadOffset readOffset)
      Create a consumer group.
      Parameters:
      key - the key the stream is stored at.
      groupName - name of the consumer group to create.
      readOffset - the offset to start at.
      Returns:
      ok if successful. null when used in pipeline / transaction.
    • xGroupCreate

      @Nullable String xGroupCreate(byte[] key, String groupName, ReadOffset readOffset, boolean mkStream)
      Create a consumer group.
      Parameters:
      key - the key the stream is stored at.
      groupName - name of the consumer group to create.
      readOffset - the offset to start at.
      mkStream - if true the group will create the stream if not already present (MKSTREAM)
      Returns:
      ok if successful. null when used in pipeline / transaction.
      Since:
      2.3
    • xGroupDelConsumer

      @Nullable default Boolean xGroupDelConsumer(byte[] key, String groupName, String consumerName)
      Delete a consumer from a consumer group.
      Parameters:
      key - the key the stream is stored at.
      groupName - the name of the group to remove the consumer from.
      consumerName - the name of the consumer to remove from the group.
      Returns:
      true if successful. null when used in pipeline / transaction.
    • xGroupDelConsumer

      @Nullable Boolean xGroupDelConsumer(byte[] key, Consumer consumer)
      Delete a consumer from a consumer group.
      Parameters:
      key - the key the stream is stored at.
      consumer - consumer identified by group name and consumer name.
      Returns:
      true if successful. null when used in pipeline / transaction.
    • xGroupDestroy

      @Nullable Boolean xGroupDestroy(byte[] key, String groupName)
      Destroy a consumer group.
      Parameters:
      key - the key the stream is stored at.
      groupName - name of the consumer group.
      Returns:
      true if successful. null when used in pipeline / transaction.
    • xInfo

      @Nullable StreamInfo.XInfoStream xInfo(byte[] key)
      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
    • xInfoGroups

      @Nullable StreamInfo.XInfoGroups xInfoGroups(byte[] key)
      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
    • xInfoConsumers

      @Nullable StreamInfo.XInfoConsumers xInfoConsumers(byte[] key, String groupName)
      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.
      groupName - name of the consumer group.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.3
    • xLen

      @Nullable Long xLen(byte[] key)
      Get the length of a stream.
      Parameters:
      key - the key the stream is stored at.
      Returns:
      length of the stream. null when used in pipeline / transaction.
      See Also:
    • xPending

      @Nullable PendingMessagesSummary xPending(byte[] key, String groupName)
      Obtain the PendingMessagesSummary for a given consumer group.
      Parameters:
      key - the key the stream is stored at. Must not be null.
      groupName - 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:
    • xPending

      @Nullable default PendingMessages xPending(byte[] 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:
    • xPending

      @Nullable default PendingMessages xPending(byte[] key, String groupName, String consumerName)
      Obtained detailed information about all pending messages for a given consumer.
      Parameters:
      key - the key the stream is stored at. Must not be null.
      groupName - the name of the consumer group. Must not be null.
      consumerName - 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:
    • xPending

      @Nullable default PendingMessages xPending(byte[] key, String groupName, 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.
      groupName - 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. Must not be null.
      Returns:
      pending messages for the given consumer group or null when used in pipeline / transaction.
      Since:
      2.3
      See Also:
    • xPending

      @Nullable default PendingMessages xPending(byte[] 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. Must not be null.
      Returns:
      pending messages for the given Consumer or null when used in pipeline / transaction.
      Since:
      2.3
      See Also:
    • xPending

      @Nullable default PendingMessages xPending(byte[] key, String groupName, String consumerName, 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.
      groupName - the name of the consumer group. Must not be null.
      consumerName - 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. Must not be null.
      Returns:
      pending messages for the given consumer in given consumer group or null when used in pipeline / transaction.
      Since:
      2.3
      See Also:
    • xPending

      @Nullable PendingMessages xPending(byte[] key, String groupName, RedisStreamCommands.XPendingOptions options)
      Obtain detailed information about pending messages applying given options.
      Parameters:
      key - the key the stream is stored at. Must not be null.
      groupName - the name of the consumer group. Must not be null.
      options - the options containing range, consumer and count. Must not be null.
      Returns:
      pending messages matching given criteria or null when used in pipeline / transaction.
      Since:
      2.3
      See Also:
    • xRange

      @Nullable default List<ByteRecord> xRange(byte[] key, Range<String> range)
      Retrieve all records within a specific Range from the stream stored at key.
      Use Range.unbounded() to read from the minimum and the maximum ID possible.
      Parameters:
      key - the key the stream is stored at.
      range - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • xRange

      @Nullable List<ByteRecord> xRange(byte[] key, Range<String> range, Limit limit)
      Retrieve a limited number of records within a specific Range from the stream stored at key.
      Use Range.unbounded() to read from the minimum and the maximum ID possible.
      Use Limit.unlimited() to read all records.
      Parameters:
      key - the key the stream is stored at.
      range - must not be null.
      limit - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • xRead

      @Nullable default List<ByteRecord> xRead(StreamOffset<byte[]>... streams)
      Read records from one or more StreamOffsets.
      Parameters:
      streams - the streams to read from.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • xRead

      @Nullable List<ByteRecord> xRead(StreamReadOptions readOptions, StreamOffset<byte[]>... streams)
      Read records from one or more StreamOffsets.
      Parameters:
      readOptions - read arguments.
      streams - the streams to read from.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • xReadGroup

      @Nullable default List<ByteRecord> xReadGroup(Consumer consumer, StreamOffset<byte[]>... 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:
    • xReadGroup

      @Nullable List<ByteRecord> xReadGroup(Consumer consumer, StreamReadOptions readOptions, StreamOffset<byte[]>... 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:
    • xRevRange

      @Nullable default List<ByteRecord> xRevRange(byte[] 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:
    • xRevRange

      @Nullable List<ByteRecord> xRevRange(byte[] 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:
    • xTrim

      @Nullable Long xTrim(byte[] 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:
    • xTrim

      @Nullable Long xTrim(byte[] 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: