From 4f2975fe6b425c92d19ffd0dabbc515e1423cd77 Mon Sep 17 00:00:00 2001 From: dengliming Date: Sat, 27 Feb 2021 23:44:36 +0800 Subject: [PATCH] LPOP and RPOP with count option --- .../DefaultStringRedisConnection.java | 36 ++++++++++ .../connection/DefaultedRedisConnection.java | 15 +++++ .../connection/ReactiveListCommands.java | 67 +++++++++++++++++-- .../redis/connection/RedisListCommands.java | 23 +++++++ .../connection/StringRedisConnection.java | 22 ++++++ .../jedis/JedisClusterListCommands.java | 33 +++++++++ .../connection/jedis/JedisListCommands.java | 25 +++++++ .../lettuce/LettuceListCommands.java | 25 +++++++ .../lettuce/LettuceReactiveListCommands.java | 22 +++++- .../redis/core/DefaultListOperations.java | 21 ++++++ .../data/redis/core/ListOperations.java | 23 +++++++ ...ultStringRedisConnectionPipelineTests.java | 28 +++++++- ...tStringRedisConnectionPipelineTxTests.java | 28 +++++++- .../DefaultStringRedisConnectionTests.java | 29 ++++++++ ...ceReactiveListCommandIntegrationTests.java | 4 ++ 15 files changed, 391 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java index 90976449bb..0fdd14e39c 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -697,6 +697,15 @@ public byte[] lPop(byte[] key) { return convertAndReturn(delegate.lPop(key), Converters.identityConverter()); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisListCommands#lPop(byte[], long) + */ + @Override + public List lPop(byte[] key, long count) { + return convertAndReturn(delegate.lPop(key, count), Converters.identityConverter()); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisListCommands#lPos(byte[], byte[], java.lang.Integer, java.lang.Integer) @@ -887,6 +896,15 @@ public byte[] rPop(byte[] key) { return convertAndReturn(delegate.rPop(key), Converters.identityConverter()); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[], long) + */ + @Override + public List rPop(byte[] key, long count) { + return convertAndReturn(delegate.rPop(key, count), Converters.identityConverter()); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisListCommands#rPopLPush(byte[], byte[]) @@ -2160,6 +2178,15 @@ public String lPop(String key) { return convertAndReturn(delegate.lPop(serialize(key)), bytesToString); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.StringRedisConnection#lPop(java.lang.String, long) + */ + @Override + public List lPop(String key, long count) { + return convertAndReturn(delegate.lPop(serialize(key), count), byteListToStringList); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.StringRedisConnection#lPos(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer) @@ -2313,6 +2340,15 @@ public String rPop(String key) { return convertAndReturn(delegate.rPop(serialize(key)), bytesToString); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.StringRedisConnection#rPop(java.lang.String, long) + */ + @Override + public List rPop(String key, long count) { + return convertAndReturn(delegate.rPop(serialize(key), count), byteListToStringList); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.StringRedisConnection#rPopLPush(java.lang.String, java.lang.String) diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java index 41c50d7f18..fa225acd43 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java @@ -56,6 +56,7 @@ * @author Mark Paluch * @author Tugdual Grall * @author Andrey Shlykov + * @author dengliming * @since 2.0 */ public interface DefaultedRedisConnection extends RedisConnection { @@ -712,6 +713,13 @@ default byte[] lPop(byte[] key) { return listCommands().lPop(key); } + /** @deprecated in favor of {@link RedisConnection#listCommands()}}. */ + @Override + @Deprecated + default List lPop(byte[] key, long count) { + return listCommands().lPop(key, count); + } + /** @deprecated in favor of {@link RedisConnection#listCommands()}}. */ @Override @Deprecated @@ -719,6 +727,13 @@ default byte[] rPop(byte[] key) { return listCommands().rPop(key); } + /** @deprecated in favor of {@link RedisConnection#listCommands()}}. */ + @Override + @Deprecated + default List rPop(byte[] key, long count) { + return listCommands().rPop(key, count); + } + /** @deprecated in favor of {@link RedisConnection#listCommands()}}. */ @Override @Deprecated diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveListCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveListCommands.java index c75690e1c2..cb71416848 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveListCommands.java @@ -42,6 +42,7 @@ * * @author Christoph Strobl * @author Mark Paluch + * @author dengliming * @since 2.0 */ public interface ReactiveListCommands { @@ -874,12 +875,14 @@ default Mono lRem(ByteBuffer key, Long count, ByteBuffer value) { */ class PopCommand extends KeyCommand { + private final long count; + private final Direction direction; - private PopCommand(@Nullable ByteBuffer key, Direction direction) { + private PopCommand(@Nullable ByteBuffer key, long count, Direction direction) { super(key); - + this.count = count; this.direction = direction; } @@ -889,7 +892,7 @@ private PopCommand(@Nullable ByteBuffer key, Direction direction) { * @return a new {@link PopCommand} for right push ({@literal RPOP}). */ public static PopCommand right() { - return new PopCommand(null, Direction.RIGHT); + return new PopCommand(null, 0, Direction.RIGHT); } /** @@ -898,7 +901,7 @@ public static PopCommand right() { * @return a new {@link PopCommand} for right push ({@literal LPOP}). */ public static PopCommand left() { - return new PopCommand(null, Direction.LEFT); + return new PopCommand(null, 0, Direction.LEFT); } /** @@ -911,7 +914,17 @@ public PopCommand from(ByteBuffer key) { Assert.notNull(key, "Key must not be null!"); - return new PopCommand(key, direction); + return new PopCommand(key, count, direction); + } + + /** + * Applies the {@literal key}. Constructs a new command instance with all previously configured properties. + * + * @param count + * @return a new {@link LSetCommand} with {@literal value} applied. + */ + public PopCommand count(long count) { + return new PopCommand(getKey(), count, direction); } /** @@ -920,6 +933,10 @@ public PopCommand from(ByteBuffer key) { public Direction getDirection() { return direction; } + + public long getCount() { + return count; + } } /** @@ -936,6 +953,21 @@ default Mono lPop(ByteBuffer key) { return pop(Mono.just(PopCommand.left().from(key))).next().map(ByteBufferResponse::getOutput); } + /** + * Removes and returns first element in list stored at {@literal key}. + * + * @param key must not be {@literal null}. + * @param count + * @return + * @see Redis Documentation: LPOP + */ + default Flux lPop(ByteBuffer key, long count) { + + Assert.notNull(key, "Key must not be null!"); + + return popList(Mono.just(PopCommand.left().from(key).count(count))).flatMap(CommandResponse::getOutput); + } + /** * Removes and returns last element in list stored at {@literal key}. * @@ -950,6 +982,21 @@ default Mono rPop(ByteBuffer key) { return pop(Mono.just(PopCommand.right().from(key))).next().map(ByteBufferResponse::getOutput); } + /** + * Removes and returns last element in list stored at {@literal key}. + * + * @param key must not be {@literal null}. + * @param count + * @return + * @see Redis Documentation: RPOP + */ + default Flux rPop(ByteBuffer key, long count) { + + Assert.notNull(key, "Key must not be null!"); + + return popList(Mono.just(PopCommand.right().from(key).count(count))).flatMap(CommandResponse::getOutput); + } + /** * Removes and returns last element in list stored at {@link KeyCommand#getKey()} * @@ -960,6 +1007,16 @@ default Mono rPop(ByteBuffer key) { */ Flux> pop(Publisher commands); + /** + * Removes and returns last element in list stored at {@link KeyCommand#getKey()} + * + * @param commands must not be {@literal null}. + * @return + * @see Redis Documentation: LPOP + * @see Redis Documentation: RPOP + */ + Flux>> popList(Publisher commands); + /** * @author Christoph Strobl * @see Redis Documentation: BLPOP diff --git a/src/main/java/org/springframework/data/redis/connection/RedisListCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisListCommands.java index 12ac4432e6..bf60d6a0a1 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisListCommands.java @@ -26,6 +26,7 @@ * @author Costin Leau * @author Christoph Strobl * @author Mark Paluch + * @author dengliming */ public interface RedisListCommands { @@ -200,6 +201,17 @@ default Long lPos(byte[] key, byte[] element) { @Nullable byte[] lPop(byte[] key); + /** + * Removes and returns first element 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 Redis Documentation: LPOP + */ + @Nullable + List lPop(byte[] key, long count); + /** * Removes and returns last element in list stored at {@code key}. * @@ -210,6 +222,17 @@ default Long lPos(byte[] key, byte[] element) { @Nullable byte[] rPop(byte[] key); + /** + * Removes and returns last element 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 Redis Documentation: RPOP + */ + @Nullable + List rPop(byte[] key, long count); + /** * Removes and returns first element from lists stored at {@code keys}.
* Blocks connection until element available or {@code timeout} reached. diff --git a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java index 8633ea3a57..13c43d8f59 100644 --- a/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/StringRedisConnection.java @@ -842,6 +842,17 @@ default Long lPos(String key, String element) { */ String lPop(String key); + /** + * Removes and returns first element in list stored at {@code key}. + * + * @param key must not be {@literal null}. + * @param count + * @return + * @see Redis Documentation: LPOP + * @see RedisListCommands#lPop(byte[], long) + */ + List lPop(String key, long count); + /** * Removes and returns last element in list stored at {@code key}. * @@ -852,6 +863,17 @@ default Long lPos(String key, String element) { */ String rPop(String key); + /** + * Removes and returns last element in list stored at {@code key}. + * + * @param key must not be {@literal null}. + * @param count + * @return + * @see Redis Documentation: RPOP + * @see RedisListCommands#rPop(byte[], long) + */ + List rPop(String key, long count); + /** * Removes and returns first element from lists stored at {@code keys} (see: {@link #lPop(byte[])}).
* Blocks connection until element available or {@code timeout} reached. diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterListCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterListCommands.java index 78ebc6ae34..38dd2aac2d 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterListCommands.java @@ -33,6 +33,7 @@ * @author Christoph Strobl * @author Mark Paluch * @author Jot Zhao + * @author dengliming * @since 2.0 */ class JedisClusterListCommands implements RedisListCommands { @@ -269,6 +270,22 @@ public byte[] lPop(byte[] key) { } } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisListCommands#lPop(byte[], long) + */ + @Override + public List lPop(byte[] key, long count) { + + Assert.notNull(key, "Key must not be null!"); + + try { + return connection.getCluster().lpop(key, (int) count); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[]) @@ -285,6 +302,22 @@ public byte[] rPop(byte[] key) { } } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[], long) + */ + @Override + public List rPop(byte[] key, long count) { + + Assert.notNull(key, "Key must not be null!"); + + try { + return connection.getCluster().rpop(key, (int) count); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisListCommands#bLPop(int, byte[][]) diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisListCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisListCommands.java index 0aabd94e0f..c354e0c139 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisListCommands.java @@ -30,6 +30,7 @@ /** * @author Christoph Strobl * @author Mark Paluch + * @author dengliming * @since 2.0 */ class JedisListCommands implements RedisListCommands { @@ -214,6 +215,18 @@ public byte[] lPop(byte[] key) { return connection.invoke().just(BinaryJedis::lpop, MultiKeyPipelineBase::lpop, key); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisListCommands#lPop(byte[], long) + */ + @Override + public List lPop(byte[] key, long count) { + + Assert.notNull(key, "Key must not be null!"); + + return connection.invoke().just(BinaryJedis::lpop, MultiKeyPipelineBase::lpop, key, (int) count); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[]) @@ -226,6 +239,18 @@ public byte[] rPop(byte[] key) { return connection.invoke().just(BinaryJedis::rpop, MultiKeyPipelineBase::rpop, key); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[], long) + */ + @Override + public List rPop(byte[] key, long count) { + + Assert.notNull(key, "Key must not be null!"); + + return connection.invoke().just(BinaryJedis::rpop, MultiKeyPipelineBase::rpop, key, (int) count); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisListCommands#bLPop(int, byte[][]) diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceListCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceListCommands.java index 459f0f6252..bcd77c587b 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceListCommands.java @@ -30,6 +30,7 @@ /** * @author Christoph Strobl * @author Mark Paluch + * @author dengliming * @since 2.0 */ class LettuceListCommands implements RedisListCommands { @@ -213,6 +214,18 @@ public byte[] lPop(byte[] key) { return connection.invoke().just(RedisListAsyncCommands::lpop, key); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisListCommands#lPop(byte[], long) + */ + @Override + public List lPop(byte[] key, long count) { + + Assert.notNull(key, "Key must not be null!"); + + return connection.invoke().just(RedisListAsyncCommands::lpop, key, count); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[]) @@ -225,6 +238,18 @@ public byte[] rPop(byte[] key) { return connection.invoke().just(RedisListAsyncCommands::rpop, key); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.RedisListCommands#rPop(byte[], long) + */ + @Override + public List rPop(byte[] key, long count) { + + Assert.notNull(key, "Key must not be null!"); + + return connection.invoke().just(RedisListAsyncCommands::rpop, key, count); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.RedisListCommands#bLPop(int, byte[][]) diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommands.java index 28b08d3da0..409b103df7 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommands.java @@ -41,6 +41,7 @@ * @author Christoph Strobl * @author Mark Paluch * @author Michele Mancioppi + * @author dengliming * @since 2.0 */ class LettuceReactiveListCommands implements ReactiveListCommands { @@ -252,7 +253,7 @@ public Flux> lRem(Publisher comm /* * (non-Javadoc) - * @see org.springframework.data.redis.connection.ReactiveListCommands#rPop(org.reactivestreams.Publisher) + * @see org.springframework.data.redis.connection.ReactiveListCommands#pop(org.reactivestreams.Publisher) */ @Override public Flux> pop(Publisher commands) { @@ -270,6 +271,25 @@ public Flux> pop(Publisher commands) })); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.connection.ReactiveListCommands#popList(org.reactivestreams.Publisher) + */ + @Override + public Flux>> popList(Publisher commands) { + return connection.execute(cmd -> Flux.from(commands).concatMap(command -> { + + Assert.notNull(command.getKey(), "Key must not be null!"); + Assert.notNull(command.getDirection(), "Direction must not be null!"); + + Flux popResult = ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection()) + ? cmd.rpop(command.getKey(), command.getCount()) + : cmd.lpop(command.getKey(), command.getCount()); + + return Mono.just(new CommandResponse<>(command, popResult)); + })); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.connection.ReactiveListCommands#bPop(org.reactivestreams.Publisher) diff --git a/src/main/java/org/springframework/data/redis/core/DefaultListOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultListOperations.java index 20e824eea9..f3026f303d 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultListOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultListOperations.java @@ -30,6 +30,7 @@ * @author David Liu * @author Thomas Darimont * @author Christoph Strobl + * @author dengliming */ class DefaultListOperations extends AbstractOperations implements ListOperations { @@ -97,6 +98,16 @@ protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { }, true); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.ListOperations#leftPop(java.lang.Object, long) + */ + @Override + public List leftPop(K key, long count) { + byte[] rawKey = rawKey(key); + return execute(connection -> deserializeValues(connection.lPop(rawKey, count)), true); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.core.ListOperations#leftPop(java.lang.Object, long, java.util.concurrent.TimeUnit) @@ -227,6 +238,16 @@ protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { }, true); } + /* + * (non-Javadoc) + * @see org.springframework.data.redis.core.ListOperations#rightPop(java.lang.Object, long) + */ + @Override + public List rightPop(K key, long count) { + byte[] rawKey = rawKey(key); + return execute(connection -> deserializeValues(connection.rPop(rawKey, count)), true); + } + /* * (non-Javadoc) * @see org.springframework.data.redis.core.ListOperations#rightPop(java.lang.Object, long, java.util.concurrent.TimeUnit) diff --git a/src/main/java/org/springframework/data/redis/core/ListOperations.java b/src/main/java/org/springframework/data/redis/core/ListOperations.java index 5941635fd1..eb5a6589d3 100644 --- a/src/main/java/org/springframework/data/redis/core/ListOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ListOperations.java @@ -31,6 +31,7 @@ * @author Thomas Darimont * @author Christoph Strobl * @author Mark Paluch + * @author dengliming */ public interface ListOperations { @@ -247,6 +248,17 @@ public interface ListOperations { @Nullable V leftPop(K key); + /** + * Removes and returns first element in list stored at {@code key}. + * + * @param key must not be {@literal null}. + * @param count + * @return can be {@literal null}. + * @see Redis Documentation: LPOP + */ + @Nullable + List leftPop(K key, long count); + /** * Removes and returns first element from lists stored at {@code key} .
* Blocks connection until element available or {@code timeout} reached. @@ -290,6 +302,17 @@ default V leftPop(K key, Duration timeout) { @Nullable V rightPop(K key); + /** + * Removes and returns last element in list stored at {@code key}. + * + * @param key must not be {@literal null}. + * @param count + * @return can be {@literal null}. + * @see Redis Documentation: RPOP + */ + @Nullable + List rightPop(K key, long count); + /** * Removes and returns last element from lists stored at {@code key}.
* Blocks connection until element available or {@code timeout} reached. diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java index 84e501c269..aff3ba5b0c 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java @@ -37,6 +37,7 @@ * @author Christoph Strobl * @author Ninad Divadkar * @author Mark Paluch + * @author dengliming */ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedisConnectionTests { @@ -514,8 +515,7 @@ public void testLLen() { @Test public void testLPopBytes() { doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); - actual.add(connection.lPop(fooBytes)); - verifyResults(Arrays.asList(new Object[] { barBytes })); + super.testLPopBytes(); } @Test @@ -524,6 +524,18 @@ public void testLPop() { super.testLPop(); } + @Test + public void testLPopCountBytes() { + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); + super.testLPopCountBytes(); + } + + @Test + public void testLPopCount() { + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); + super.testLPopCount(); + } + @Test public void testLPushBytes() { doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); @@ -668,6 +680,18 @@ public void testRPop() { super.testRPop(); } + @Test + public void testRPopCountBytes() { + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); + super.testRPopCountBytes(); + } + + @Test + public void testRPopCount() { + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); + super.testRPopCount(); + } + @Test public void testRPopLPushBytes() { doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java index 882d11f595..852174a2d4 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java @@ -36,6 +36,7 @@ * @author Christoph Strobl * @author Ninad Divadkar * @author Mark Paluch + * @author dengliming */ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRedisConnectionTxTests { @@ -547,8 +548,7 @@ public void testLLen() { public void testLPopBytes() { doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); - actual.add(connection.lPop(fooBytes)); - verifyResults(Arrays.asList(new Object[] { barBytes })); + super.testLPopBytes(); } @Test @@ -558,6 +558,18 @@ public void testLPop() { super.testLPop(); } + @Test + public void testLPopCountBytes() { + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection).closePipeline(); + super.testLPopCountBytes(); + } + + @Test + public void testLPopCount() { + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection).closePipeline(); + super.testLPopCount(); + } + @Test public void testLPushBytes() { doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); @@ -718,6 +730,18 @@ public void testRPop() { super.testRPop(); } + @Test + public void testRPopCountBytes() { + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection).closePipeline(); + super.testRPopCountBytes(); + } + + @Test + public void testRPopCount() { + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection).closePipeline(); + super.testRPopCount(); + } + @Test public void testRPopLPushBytes() { doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java index b5ac42a5db..3634a5c151 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java @@ -70,6 +70,7 @@ * @author Christoph Strobl * @author Ninad Divadkar * @author Mark Paluch + * @author dengliming */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) @@ -669,6 +670,20 @@ public void testLPop() { verifyResults(Collections.singletonList(bar)); } + @Test + public void testLPopCountBytes() { + doReturn(Collections.singletonList(barBytes)).when(nativeConnection).lPop(fooBytes, 2); + actual.add(connection.lPop(fooBytes, 2)); + verifyResults(Collections.singletonList(bytesList)); + } + + @Test + public void testLPopCount() { + doReturn(Collections.singletonList(barBytes)).when(nativeConnection).lPop(fooBytes, 2); + actual.add(connection.lPop(foo, 2)); + verifyResults(Collections.singletonList(stringList)); + } + @Test public void testLPushBytes() { doReturn(8L).when(nativeConnection).lPush(fooBytes, barBytes); @@ -837,6 +852,20 @@ public void testRPop() { verifyResults(Collections.singletonList(bar)); } + @Test + public void testRPopCountBytes() { + doReturn(Collections.singletonList(barBytes)).when(nativeConnection).rPop(fooBytes, 2); + actual.add(connection.rPop(fooBytes, 2)); + verifyResults(Collections.singletonList(bytesList)); + } + + @Test + public void testRPopCount() { + doReturn(Collections.singletonList(barBytes)).when(nativeConnection).rPop(fooBytes, 2); + actual.add(connection.rPop(foo, 2)); + verifyResults(Collections.singletonList(stringList)); + } + @Test public void testRPopLPushBytes() { doReturn(barBytes).when(nativeConnection).rPopLPush(fooBytes, barBytes); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandIntegrationTests.java index f9e03625f6..282319dff3 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandIntegrationTests.java @@ -43,6 +43,7 @@ * @author Christoph Strobl * @author Mark Paluch * @author Michele Mancioppi + * @author dengliming */ public class LettuceReactiveListCommandIntegrationTests extends LettuceReactiveCommandsTestSupport { @@ -245,6 +246,9 @@ void lPopSouldRemoveFirstValueCorrectly() { assertThat(connection.listCommands().lPop(KEY_1_BBUFFER).block()).isEqualTo(VALUE_1_BBUFFER); assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_2, VALUE_3); + + assertThat(connection.listCommands().lPop(KEY_1_BBUFFER, 2).collectList().block()).isEqualTo(Arrays.asList(VALUE_2_BBUFFER, VALUE_3_BBUFFER)); + assertThat(nativeCommands.lrange(KEY_1, 0, -1)).isEmpty(); } @ParameterizedRedisTest // DATAREDIS-525