org.springframework.data.redis.core.BoundStreamOperations Maven / Gradle / Ivy
/*
* Copyright 2018-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.core;
import java.util.List;
import java.util.Map;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.connection.stream.StreamReadOptions;
import org.springframework.lang.Nullable;
/**
* Redis stream specific operations bound to a certain key.
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Dengliming
* @since 2.2
*/
public interface BoundStreamOperations {
/**
* Acknowledge one or more records as processed.
*
* @param group name of the consumer group.
* @param recordIds record Id's to acknowledge.
* @return length of acknowledged records. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XACK
*/
@Nullable
Long acknowledge(String group, String... recordIds);
/**
* Append a record to the stream {@code key}.
*
* @param body record body.
* @return the record Id. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XADD
*/
@Nullable
RecordId add(Map body);
/**
* Removes the specified entries from the stream. Returns the number of items deleted, that may be different from the
* number of IDs passed in case certain IDs do not exist.
*
* @param recordIds stream record Id's.
* @return number of removed entries. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XDEL
*/
@Nullable
Long delete(String... recordIds);
/**
* Create a consumer group.
*
* @param readOffset
* @param group name of the consumer group.
* @return {@literal true} if successful. {@literal null} when used in pipeline / transaction.
*/
@Nullable
String createGroup(ReadOffset readOffset, String group);
/**
* Delete a consumer from a consumer group.
*
* @param consumer consumer identified by group name and consumer key.
* @return {@literal true} if successful. {@literal null} when used in pipeline / transaction.
*/
@Nullable
Boolean deleteConsumer(Consumer consumer);
/**
* Destroy a consumer group.
*
* @param group name of the consumer group.
* @return {@literal true} if successful. {@literal null} when used in pipeline / transaction.
*/
@Nullable
Boolean destroyGroup(String group);
/**
* Get the length of a stream.
*
* @return length of the stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XLEN
*/
@Nullable
Long size();
/**
* Read records from a stream within a specific {@link Range}.
*
* @param range must not be {@literal null}.
* @return list with members of the resulting stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XRANGE
*/
@Nullable
default List> range(Range range) {
return range(range, Limit.unlimited());
}
/**
* Read records from a stream within a specific {@link Range} applying a {@link Limit}.
*
* @param range must not be {@literal null}.
* @param limit must not be {@literal null}.
* @return list with members of the resulting stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XRANGE
*/
@Nullable
List> range(Range range, Limit limit);
/**
* Read records from {@link ReadOffset}.
*
* @param readOffset the offset to read from.
* @return list with members of the resulting stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XREAD
*/
@Nullable
default List> read(ReadOffset readOffset) {
return read(StreamReadOptions.empty(), readOffset);
}
/**
* Read records starting from {@link ReadOffset}.
*
* @param readOptions read arguments.
* @param readOffset the offset to read from.
* @return list with members of the resulting stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XREAD
*/
@Nullable
List> read(StreamReadOptions readOptions, ReadOffset readOffset);
/**
* Read records starting from {@link ReadOffset}. using a consumer group.
*
* @param consumer consumer/group.
* @param readOffset the offset to read from.
* @return list with members of the resulting stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XREADGROUP
*/
@Nullable
default List> read(Consumer consumer, ReadOffset readOffset) {
return read(consumer, StreamReadOptions.empty(), readOffset);
}
/**
* Read records starting from {@link ReadOffset}. using a consumer group.
*
* @param consumer consumer/group.
* @param readOptions read arguments.
* @param readOffset the offset to read from.
* @return list with members of the resulting stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XREADGROUP
*/
@Nullable
List> read(Consumer consumer, StreamReadOptions readOptions, ReadOffset readOffset);
/**
* Read records from a stream within a specific {@link Range} in reverse order.
*
* @param range must not be {@literal null}.
* @return list with members of the resulting stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XREVRANGE
*/
@Nullable
default List> reverseRange(Range range) {
return reverseRange(range, Limit.unlimited());
}
/**
* Read records from a stream within a specific {@link Range} applying a {@link Limit} in reverse order.
*
* @param range must not be {@literal null}.
* @param limit must not be {@literal null}.
* @return list with members of the resulting stream. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XREVRANGE
*/
@Nullable
List> reverseRange(Range range, Limit limit);
/**
* Trims the stream to {@code count} elements.
*
* @param count length of the stream.
* @return number of removed entries. {@literal null} when used in pipeline / transaction.
* @see Redis Documentation: XTRIM
*/
@Nullable
Long trim(long count);
/**
* Trims the stream to {@code count} elements.
*
* @param count length of the stream.
* @param approximateTrimming the trimming must be performed in a approximated way in order to maximize performances.
* @return number of removed entries. {@literal null} when used in pipeline / transaction.
* @since 2.4
* @see Redis Documentation: XTRIM
*/
@Nullable
Long trim(long count, boolean approximateTrimming);
}