Polishing.
Add leftPop/rightPop methods to BoundListOperations. Tweak Javadoc and add since tags. Extend tests. Closes #1987
This commit is contained in:
@@ -922,6 +922,7 @@ public interface ReactiveListCommands {
|
||||
*
|
||||
* @param count
|
||||
* @return a new {@link LSetCommand} with {@literal value} applied.
|
||||
* @since 2.6
|
||||
*/
|
||||
public PopCommand count(long count) {
|
||||
return new PopCommand(getKey(), count, direction);
|
||||
@@ -954,12 +955,13 @@ public interface ReactiveListCommands {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and returns first element in list stored at {@literal key}.
|
||||
* Removes and returns first {@code count} elements in list stored at {@literal key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
|
||||
* @since 2.6
|
||||
*/
|
||||
default Flux<ByteBuffer> lPop(ByteBuffer key, long count) {
|
||||
|
||||
@@ -983,12 +985,13 @@ public interface ReactiveListCommands {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and returns last element in list stored at {@literal key}.
|
||||
* Removes and returns last {@code count} elements in list stored at {@literal key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
|
||||
* @since 2.6
|
||||
*/
|
||||
default Flux<ByteBuffer> rPop(ByteBuffer key, long count) {
|
||||
|
||||
|
||||
@@ -202,12 +202,13 @@ public interface RedisListCommands {
|
||||
byte[] lPop(byte[] key);
|
||||
|
||||
/**
|
||||
* Removes and returns first element in list stored at {@code key}.
|
||||
* Removes and returns first {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return {@literal null} when key does not exist or used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
|
||||
* @since 2.6
|
||||
*/
|
||||
@Nullable
|
||||
List<byte[]> lPop(byte[] key, long count);
|
||||
@@ -223,12 +224,13 @@ public interface RedisListCommands {
|
||||
byte[] rPop(byte[] key);
|
||||
|
||||
/**
|
||||
* Removes and returns last element in list stored at {@code key}.
|
||||
* Removes and returns last {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return {@literal null} when key does not exist or used in pipeline / transaction.
|
||||
* @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
|
||||
* @since 2.6
|
||||
*/
|
||||
@Nullable
|
||||
List<byte[]> rPop(byte[] key, long count);
|
||||
|
||||
@@ -843,13 +843,14 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
String lPop(String key);
|
||||
|
||||
/**
|
||||
* Removes and returns first element in list stored at {@code key}.
|
||||
* Removes and returns first {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
|
||||
* @see RedisListCommands#lPop(byte[], long)
|
||||
* @since 2.6
|
||||
*/
|
||||
List<String> lPop(String key, long count);
|
||||
|
||||
@@ -864,13 +865,14 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
String rPop(String key);
|
||||
|
||||
/**
|
||||
* Removes and returns last element in list stored at {@code key}.
|
||||
* Removes and returns last {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
|
||||
* @see RedisListCommands#rPop(byte[], long)
|
||||
* @since 2.6
|
||||
*/
|
||||
List<String> rPop(String key, long count);
|
||||
|
||||
|
||||
@@ -277,6 +277,7 @@ class LettuceReactiveListCommands implements ReactiveListCommands {
|
||||
*/
|
||||
@Override
|
||||
public Flux<CommandResponse<PopCommand, Flux<ByteBuffer>>> popList(Publisher<PopCommand> commands) {
|
||||
|
||||
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
|
||||
|
||||
Assert.notNull(command.getKey(), "Key must not be null!");
|
||||
|
||||
@@ -200,6 +200,18 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {
|
||||
@Nullable
|
||||
V leftPop();
|
||||
|
||||
/**
|
||||
* Removes and returns first {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return can be {@literal null}.
|
||||
* @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
|
||||
* @since 2.6
|
||||
*/
|
||||
@Nullable
|
||||
List<V> leftPop(long count);
|
||||
|
||||
/**
|
||||
* Removes and returns first element from lists stored at the bound key . <br>
|
||||
* <b>Blocks connection</b> until element available or {@code timeout} reached.
|
||||
@@ -240,6 +252,18 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {
|
||||
@Nullable
|
||||
V rightPop();
|
||||
|
||||
/**
|
||||
* Removes and returns last {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return can be {@literal null}.
|
||||
* @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
|
||||
* @since 2.6
|
||||
*/
|
||||
@Nullable
|
||||
List<V> rightPop(long count);
|
||||
|
||||
/**
|
||||
* Removes and returns last element from lists stored at the bound key. <br>
|
||||
* <b>Blocks connection</b> until element available or {@code timeout} reached.
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Default implementation for {@link BoundListOperations}.
|
||||
@@ -82,6 +83,15 @@ class DefaultBoundListOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.leftPop(getKey());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundListOperations#leftPop(long)
|
||||
*/
|
||||
@Override
|
||||
public List<V> leftPop(long count) {
|
||||
return ops.leftPop(getKey(), count);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundListOperations#leftPop(long, java.util.concurrent.TimeUnit)
|
||||
@@ -163,6 +173,15 @@ class DefaultBoundListOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.rightPop(getKey());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundListOperations#rightPop(long)
|
||||
*/
|
||||
@Override
|
||||
public List<V> rightPop(long count) {
|
||||
return ops.rightPop(getKey(), count);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundListOperations#rightPop(long, java.util.concurrent.TimeUnit)
|
||||
|
||||
@@ -249,12 +249,13 @@ public interface ListOperations<K, V> {
|
||||
V leftPop(K key);
|
||||
|
||||
/**
|
||||
* Removes and returns first element in list stored at {@code key}.
|
||||
* Removes and returns first {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return can be {@literal null}.
|
||||
* @see <a href="https://redis.io/commands/lpop">Redis Documentation: LPOP</a>
|
||||
* @since 2.6
|
||||
*/
|
||||
@Nullable
|
||||
List<V> leftPop(K key, long count);
|
||||
@@ -303,12 +304,13 @@ public interface ListOperations<K, V> {
|
||||
V rightPop(K key);
|
||||
|
||||
/**
|
||||
* Removes and returns last element in list stored at {@code key}.
|
||||
* Removes and returns last {@code} elements in list stored at {@code key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param count
|
||||
* @return can be {@literal null}.
|
||||
* @see <a href="https://redis.io/commands/rpop">Redis Documentation: RPOP</a>
|
||||
* @since 2.6
|
||||
*/
|
||||
@Nullable
|
||||
List<V> rightPop(K key, long count);
|
||||
|
||||
Reference in New Issue
Block a user