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 b9afb28f5..733a0b299 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java @@ -75,6 +75,7 @@ import org.springframework.util.ObjectUtils; * @author Andrey Shlykov * @author dengliming * @author ihaohong + * @author Dennis Neufeld */ public class DefaultStringRedisConnection implements StringRedisConnection, DecoratedRedisConnection { @@ -313,11 +314,21 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco delegate.flushAll(); } + @Override + public void flushAll(FlushOption option) { + delegate.flushAll(option); + } + @Override public void flushDb() { delegate.flushDb(); } + @Override + public void flushDb(FlushOption option) { + delegate.flushDb(option); + } + @Override public byte[] get(byte[] key) { return convertAndReturn(delegate.get(key), Converters.identityConverter()); diff --git a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisClusterConnection.java index fb853a0be..4fba9aa18 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisClusterConnection.java @@ -27,6 +27,7 @@ import org.springframework.util.Assert; /** * @author Christoph Strobl * @author Mark Paluch + * @author Dennis Neufeld * @since 2.0 */ public interface DefaultedRedisClusterConnection extends RedisClusterConnection, DefaultedRedisConnection { @@ -73,6 +74,13 @@ public interface DefaultedRedisClusterConnection extends RedisClusterConnection, serverCommands().flushDb(node); } + /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */ + @Override + @Deprecated + default void flushDb(RedisClusterNode node, FlushOption option) { + serverCommands().flushDb(node, option); + } + /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */ @Override @Deprecated @@ -80,6 +88,13 @@ public interface DefaultedRedisClusterConnection extends RedisClusterConnection, serverCommands().flushAll(node); } + /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */ + @Override + @Deprecated + default void flushAll(RedisClusterNode node, FlushOption option) { + serverCommands().flushAll(node, option); + } + /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */ @Override @Deprecated 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 624298bdb..69e685f37 100644 --- a/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java @@ -60,6 +60,7 @@ import org.springframework.lang.Nullable; * @author Andrey Shlykov * @author dengliming * @author ihaohong + * @author Dennis Neufeld * @since 2.0 */ public interface DefaultedRedisConnection extends RedisConnection { @@ -1632,6 +1633,13 @@ public interface DefaultedRedisConnection extends RedisConnection { serverCommands().flushDb(); } + /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */ + @Override + @Deprecated + default void flushDb(FlushOption option) { + serverCommands().flushDb(option); + } + /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */ @Override @Deprecated @@ -1639,6 +1647,13 @@ public interface DefaultedRedisConnection extends RedisConnection { serverCommands().flushAll(); } + /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */ + @Override + @Deprecated + default void flushAll(FlushOption option) { + serverCommands().flushAll(option); + } + /** @deprecated in favor of {@link RedisConnection#serverCommands()}. */ @Override @Deprecated diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterServerCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterServerCommands.java index 39077ed2d..40d497d98 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveClusterServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveClusterServerCommands.java @@ -20,6 +20,7 @@ import reactor.core.publisher.Mono; import java.util.Properties; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.core.types.RedisClientInfo; /** @@ -27,6 +28,7 @@ import org.springframework.data.redis.core.types.RedisClientInfo; * * @author Mark Paluch * @author Christoph Strobl + * @author Dennis Neufeld * @since 2.0 */ public interface ReactiveClusterServerCommands extends ReactiveServerCommands { @@ -91,6 +93,17 @@ public interface ReactiveClusterServerCommands extends ReactiveServerCommands { */ Mono flushDb(RedisClusterNode node); + /** + * Delete all keys of the currently selected database using the specified flush option. + * + * @param node must not be {@literal null}. {@link Mono} indicating command completion. + * @param option + * @throws IllegalArgumentException when {@code node} is {@literal null}. + * @see RedisServerCommands#flushDb(FlushOption) + * @since 2.6 + */ + Mono flushDb(RedisClusterNode node, FlushOption option); + /** * Delete all all keys from all databases. * @@ -101,6 +114,18 @@ public interface ReactiveClusterServerCommands extends ReactiveServerCommands { */ Mono flushAll(RedisClusterNode node); + /** + * Delete all all keys from all databases using the specified flush option. + * + * @param node must not be {@literal null}. + * @param option + * @return {@link Mono} indicating command completion. + * @throws IllegalArgumentException when {@code node} is {@literal null}. + * @see RedisServerCommands#flushAll(FlushOption) + * @since 2.6 + */ + Mono flushAll(RedisClusterNode node, FlushOption option); + /** * Load {@literal default} server information like *
    diff --git a/src/main/java/org/springframework/data/redis/connection/ReactiveServerCommands.java b/src/main/java/org/springframework/data/redis/connection/ReactiveServerCommands.java index e792b9dc1..c1f8c9a90 100644 --- a/src/main/java/org/springframework/data/redis/connection/ReactiveServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/ReactiveServerCommands.java @@ -21,6 +21,7 @@ import reactor.core.publisher.Mono; import java.util.Properties; import java.util.concurrent.TimeUnit; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.core.types.RedisClientInfo; /** @@ -28,6 +29,7 @@ import org.springframework.data.redis.core.types.RedisClientInfo; * * @author Mark Paluch * @author Christoph Strobl + * @author Dennis Neufeld * @since 2.0 */ public interface ReactiveServerCommands { @@ -81,6 +83,16 @@ public interface ReactiveServerCommands { */ Mono flushDb(); + /** + * Delete all keys of the currently selected database using the specified flush option. + * + * @param option + * @return {@link Mono} indicating command completion. + * @see Redis Documentation: FLUSHDB + * @since 2.6 + */ + Mono flushDb(FlushOption option); + /** * Delete all all keys from all databases. * @@ -89,6 +101,16 @@ public interface ReactiveServerCommands { */ Mono flushAll(); + /** + * Delete all all keys from all databases using the specified flush option. + * + * @param option + * @return {@link Mono} indicating command completion. + * @see Redis Documentation: FLUSHALL + * @since 2.6 + */ + Mono flushAll(FlushOption option); + /** * Load {@literal default} server information like *
      diff --git a/src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java index 20e83d35e..362d044ce 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java @@ -23,6 +23,7 @@ import org.springframework.data.redis.core.types.RedisClientInfo; /** * @author Mark Paluch + * @author Dennis Neufeld * @since 2.0 */ public interface RedisClusterServerCommands extends RedisServerCommands { @@ -65,12 +66,28 @@ public interface RedisClusterServerCommands extends RedisServerCommands { */ void flushDb(RedisClusterNode node); + /** + * @param node must not be {@literal null}. + * @param option + * @see RedisServerCommands#flushDb(FlushOption) + * @since 2.6 + */ + void flushDb(RedisClusterNode node, FlushOption option); + /** * @param node must not be {@literal null}. * @see RedisServerCommands#flushAll() */ void flushAll(RedisClusterNode node); + /** + * @param node must not be {@literal null}. + * @param option + * @see RedisServerCommands#flushAll(FlushOption) + * @since 2.6 + */ + void flushAll(RedisClusterNode node, FlushOption option); + /** * @param node must not be {@literal null}. * @return diff --git a/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java b/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java index ea7f7fb3d..86686f33f 100644 --- a/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java @@ -29,6 +29,7 @@ import org.springframework.lang.Nullable; * @author Christoph Strobl * @author Thomas Darimont * @author Mark Paluch + * @author Dennis Neufeld */ public interface RedisServerCommands { @@ -43,6 +44,13 @@ public interface RedisServerCommands { COPY, REPLACE } + /** + * @since 2.6 + */ + enum FlushOption { + SYNC, ASYNC + } + /** * Start an {@literal Append Only File} rewrite process on server. * @@ -101,6 +109,15 @@ public interface RedisServerCommands { */ void flushDb(); + /** + * Delete all keys of the currently selected database using the specified flush option. + * + * @param option + * @see Redis Documentation: FLUSHDB + * @since 2.6 + */ + void flushDb(FlushOption option); + /** * Delete all all keys from all databases. * @@ -108,6 +125,15 @@ public interface RedisServerCommands { */ void flushAll(); + /** + * Delete all all keys from all databases using the specified flush option. + * + * @param option + * @see Redis Documentation: FLUSHALL + * @since 2.6 + */ + void flushAll(FlushOption option); + /** * Load {@literal default} server information like *
        diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterServerCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterServerCommands.java index 047cb29e7..0c92c51ca 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterServerCommands.java @@ -17,6 +17,7 @@ package org.springframework.data.redis.connection.jedis; import redis.clients.jedis.BinaryJedis; import redis.clients.jedis.Jedis; +import redis.clients.jedis.args.FlushMode; import java.util.ArrayList; import java.util.Collection; @@ -41,6 +42,7 @@ import org.springframework.util.CollectionUtils; /** * @author Mark Paluch + * @author Dennis Neufeld * @since 2.0 */ class JedisClusterServerCommands implements RedisClusterServerCommands { @@ -127,22 +129,43 @@ class JedisClusterServerCommands implements RedisClusterServerCommands { executeCommandOnAllNodes(BinaryJedis::flushDB); } + @Override + public void flushDb(FlushOption option) { + executeCommandOnAllNodes(it -> it.flushDB(toFlushMode(option))); + } + @Override public void flushDb(RedisClusterNode node) { executeCommandOnSingleNode(BinaryJedis::flushDB, node); } + @Override + public void flushDb(RedisClusterNode node, FlushOption option) { + executeCommandOnSingleNode(it -> it.flushDB(toFlushMode(option)), node); + } + @Override public void flushAll() { connection.getClusterCommandExecutor() .executeCommandOnAllNodes((JedisClusterCommandCallback) BinaryJedis::flushAll); } + @Override + public void flushAll(FlushOption option) { + connection.getClusterCommandExecutor() + .executeCommandOnAllNodes((JedisClusterCommandCallback) it -> it.flushAll(toFlushMode(option))); + } + @Override public void flushAll(RedisClusterNode node) { executeCommandOnSingleNode(BinaryJedis::flushAll, node); } + @Override + public void flushAll(RedisClusterNode node, FlushOption option) { + executeCommandOnSingleNode(it -> it.flushAll(toFlushMode(option)), node); + } + @Override public Properties info() { @@ -395,4 +418,19 @@ class JedisClusterServerCommands implements RedisClusterServerCommands { private MultiNodeResult executeCommandOnAllNodes(JedisClusterCommandCallback cmd) { return connection.getClusterCommandExecutor().executeCommandOnAllNodes(cmd); } + + static FlushMode toFlushMode(@Nullable FlushOption option) { + + if (option == null) { + return FlushMode.SYNC; + } + + switch (option) { + case ASYNC: + return FlushMode.ASYNC; + case SYNC: + return FlushMode.SYNC; + } + throw new UnsupportedOperationException("Flush option " + option + " is not implemented."); + } } diff --git a/src/main/java/org/springframework/data/redis/connection/jedis/JedisServerCommands.java b/src/main/java/org/springframework/data/redis/connection/jedis/JedisServerCommands.java index 5a2f5287b..f5f576020 100644 --- a/src/main/java/org/springframework/data/redis/connection/jedis/JedisServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/jedis/JedisServerCommands.java @@ -18,6 +18,7 @@ package org.springframework.data.redis.connection.jedis; import redis.clients.jedis.BinaryJedis; import redis.clients.jedis.Jedis; import redis.clients.jedis.MultiKeyPipelineBase; +import redis.clients.jedis.args.FlushMode; import redis.clients.jedis.args.SaveMode; import java.util.List; @@ -33,6 +34,7 @@ import org.springframework.util.Assert; /** * @author Mark Paluch + * @author Dennis Neufeld * @since 2.0 */ class JedisServerCommands implements RedisServerCommands { @@ -75,11 +77,25 @@ class JedisServerCommands implements RedisServerCommands { connection.invokeStatus().just(BinaryJedis::flushDB, MultiKeyPipelineBase::flushDB); } + @Override + public void flushDb(FlushOption option) { + + FlushMode flushMode = JedisClusterServerCommands.toFlushMode(option); + connection.invokeStatus().just(it -> it.flushDB(flushMode), it -> it.flushDB(flushMode)); + } + @Override public void flushAll() { connection.invokeStatus().just(BinaryJedis::flushAll, MultiKeyPipelineBase::flushAll); } + @Override + public void flushAll(FlushOption option) { + + FlushMode flushMode = JedisClusterServerCommands.toFlushMode(option); + connection.invokeStatus().just(it -> it.flushAll(flushMode), it -> it.flushAll(flushMode)); + } + @Override public Properties info() { return connection.invoke().from(BinaryJedis::info, MultiKeyPipelineBase::info).get(JedisConverters::toProperties); diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java index 17aa4d302..5c11e15b8 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java @@ -38,6 +38,7 @@ import org.springframework.util.CollectionUtils; /** * @author Mark Paluch + * @author Dennis Neufeld * @since 2.0 */ class LettuceClusterServerCommands extends LettuceServerCommands implements RedisClusterServerCommands { @@ -96,21 +97,41 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi executeCommandOnAllNodes(RedisServerCommands::flushdb); } + @Override + public void flushDb(FlushOption option) { + executeCommandOnAllNodes(it -> it.flushdb(toFlushMode(option))); + } + @Override public void flushDb(RedisClusterNode node) { executeCommandOnSingleNode(RedisServerCommands::flushdb, node); } + @Override + public void flushDb(RedisClusterNode node, FlushOption option) { + executeCommandOnSingleNode(it -> it.flushdb(toFlushMode(option)), node); + } + @Override public void flushAll() { executeCommandOnAllNodes(RedisServerCommands::flushall); } + @Override + public void flushAll(FlushOption option) { + executeCommandOnAllNodes(it -> it.flushall(toFlushMode(option))); + } + @Override public void flushAll(RedisClusterNode node) { executeCommandOnSingleNode(RedisServerCommands::flushall, node); } + @Override + public void flushAll(RedisClusterNode node, FlushOption option) { + executeCommandOnSingleNode(it -> it.flushall(toFlushMode(option)), node); + } + @Override public Properties info(RedisClusterNode node) { return LettuceConverters.toProperties(executeCommandOnSingleNode(RedisServerCommands::info, node).getValue()); diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java index 80b076d71..4cd684c94 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java @@ -41,6 +41,7 @@ import org.reactivestreams.Publisher; import org.springframework.data.redis.connection.ClusterTopologyProvider; import org.springframework.data.redis.connection.ReactiveClusterServerCommands; import org.springframework.data.redis.connection.RedisClusterNode; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.data.redis.util.ByteUtils; import org.springframework.util.Assert; @@ -50,6 +51,7 @@ import org.springframework.util.Assert; * * @author Mark Paluch * @author Christoph Strobl + * @author Dennis Neufeld * @since 2.0 */ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands @@ -105,11 +107,21 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands return connection.execute(node, RedisServerReactiveCommands::flushdb).next(); } + @Override + public Mono flushDb(RedisClusterNode node, FlushOption option) { + return connection.execute(node, it -> it.flushdb(LettuceServerCommands.toFlushMode(option))).next(); + } + @Override public Mono flushAll(RedisClusterNode node) { return connection.execute(node, RedisServerReactiveCommands::flushall).next(); } + @Override + public Mono flushAll(RedisClusterNode node, FlushOption option) { + return connection.execute(node, it -> it.flushall(LettuceServerCommands.toFlushMode(option))).next(); + } + @Override public Mono info() { return Flux.merge(executeOnAllNodes(this::info)).collect(PropertiesCollector.INSTANCE); diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java index 2c7c53d45..283f4bc9c 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommands.java @@ -25,6 +25,7 @@ import java.util.Properties; import java.util.concurrent.TimeUnit; import org.springframework.data.redis.connection.ReactiveServerCommands; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.data.redis.util.ByteUtils; import org.springframework.util.Assert; @@ -34,6 +35,7 @@ import org.springframework.util.Assert; * * @author Mark Paluch * @author Christoph Strobl + * @author Dennis Neufeld */ class LettuceReactiveServerCommands implements ReactiveServerCommands { @@ -82,11 +84,21 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands { return connection.execute(RedisServerReactiveCommands::flushdb).next(); } + @Override + public Mono flushDb(FlushOption option) { + return connection.execute(it -> it.flushdb(LettuceServerCommands.toFlushMode(option))).next(); + } + @Override public Mono flushAll() { return connection.execute(RedisServerReactiveCommands::flushall).next(); } + @Override + public Mono flushAll(FlushOption option) { + return connection.execute(it -> it.flushall(LettuceServerCommands.toFlushMode(option))).next(); + } + @Override public Mono info() { diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java index 660578683..a9112844c 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceServerCommands.java @@ -15,6 +15,7 @@ */ package org.springframework.data.redis.connection.lettuce; +import io.lettuce.core.FlushMode; import io.lettuce.core.LettuceFutures; import io.lettuce.core.RedisFuture; import io.lettuce.core.api.async.RedisKeyAsyncCommands; @@ -34,6 +35,7 @@ import org.springframework.util.Assert; /** * @author Mark Paluch + * @author Dennis Neufeld * @since 2.0 */ class LettuceServerCommands implements RedisServerCommands { @@ -74,11 +76,21 @@ class LettuceServerCommands implements RedisServerCommands { connection.invokeStatus().just(RedisServerAsyncCommands::flushdb); } + @Override + public void flushDb(FlushOption option) { + connection.invoke().just(it -> it.flushdb(toFlushMode(option))); + } + @Override public void flushAll() { connection.invokeStatus().just(RedisServerAsyncCommands::flushall); } + @Override + public void flushAll(FlushOption option) { + connection.invokeStatus().just(it -> it.flushall(toFlushMode(option))); + } + @Override public Properties info() { return connection.invoke().from(RedisServerAsyncCommands::info).get(LettuceConverters.stringToProps()); @@ -221,6 +233,21 @@ class LettuceServerCommands implements RedisServerCommands { return connection.getConnection(); } + static FlushMode toFlushMode(@Nullable FlushOption option) { + + if (option == null) { + return FlushMode.SYNC; + } + + switch (option) { + case ASYNC: + return FlushMode.ASYNC; + case SYNC: + return FlushMode.SYNC; + } + throw new UnsupportedOperationException("Flush option " + option + " is not implemented."); + } + static class CompletedRedisFuture extends CompletableFuture implements RedisFuture { public CompletedRedisFuture(T value) { diff --git a/src/main/java/org/springframework/data/redis/core/ClusterOperations.java b/src/main/java/org/springframework/data/redis/core/ClusterOperations.java index 620103da9..64396b55e 100644 --- a/src/main/java/org/springframework/data/redis/core/ClusterOperations.java +++ b/src/main/java/org/springframework/data/redis/core/ClusterOperations.java @@ -22,6 +22,7 @@ import org.springframework.data.redis.connection.RedisClusterCommands; import org.springframework.data.redis.connection.RedisClusterNode; import org.springframework.data.redis.connection.RedisClusterNode.SlotRange; import org.springframework.data.redis.connection.RedisConnection; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; /** * Redis operations for cluster specific operations. A {@link RedisClusterNode} can be obtained from @@ -31,6 +32,7 @@ import org.springframework.data.redis.connection.RedisConnection; * * @author Christoph Strobl * @author Mark Paluch + * @author Dennis Neufeld * @since 1.7 */ public interface ClusterOperations { @@ -117,6 +119,16 @@ public interface ClusterOperations { */ void flushDb(RedisClusterNode node); + /** + * Flush db on node using the specified flush option. + * + * @param node must not be {@literal null}. + * @param option + * @see RedisConnection#flushDb(FlushOption) + * @since 2.6 + */ + void flushDb(RedisClusterNode node, FlushOption option); + /** * @param node must not be {@literal null}. * @return diff --git a/src/main/java/org/springframework/data/redis/core/DefaultClusterOperations.java b/src/main/java/org/springframework/data/redis/core/DefaultClusterOperations.java index cef665943..36ced7401 100644 --- a/src/main/java/org/springframework/data/redis/core/DefaultClusterOperations.java +++ b/src/main/java/org/springframework/data/redis/core/DefaultClusterOperations.java @@ -23,6 +23,7 @@ import org.springframework.data.redis.connection.RedisClusterCommands.AddSlots; import org.springframework.data.redis.connection.RedisClusterConnection; import org.springframework.data.redis.connection.RedisClusterNode; import org.springframework.data.redis.connection.RedisClusterNode.SlotRange; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.connection.RedisServerCommands.MigrateOption; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -31,6 +32,7 @@ import org.springframework.util.Assert; * Default {@link ClusterOperations} implementation. * * @author Christoph Strobl + * @author Dennis Neufeld * @since 1.7 * @param * @param @@ -149,6 +151,17 @@ class DefaultClusterOperations extends AbstractOperations implements }); } + @Override + public void flushDb(RedisClusterNode node, FlushOption option) { + + Assert.notNull(node, "ClusterNode must not be null."); + + doInCluster((RedisClusterCallback) connection -> { + connection.flushDb(node, option); + return null; + }); + } + @Override public Collection getSlaves(final RedisClusterNode node) { diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java b/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java index 8ff06b624..9ce9cf41d 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java @@ -486,10 +486,6 @@ public class ReactiveRedisTemplate implements ReactiveRedisOperations Flux execute(RedisScript script, List keys, List args) { return reactiveScriptExecutor.execute(script, keys, args); diff --git a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java index 3c2fe5749..0b6b2e293 100644 --- a/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java +++ b/src/main/java/org/springframework/data/redis/support/collections/DefaultRedisSet.java @@ -203,10 +203,6 @@ public class DefaultRedisSet extends AbstractRedisCollection implements Re return DataType.SET; } - /* - * (non-Javadoc) - * @see org.springframework.data.redis.support.collections.RedisSet#scan() - */ @Override public Cursor scan() { return scan(ScanOptions.NONE); diff --git a/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java index cd2488e34..3268fd6c0 100644 --- a/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java @@ -20,6 +20,7 @@ import org.springframework.data.geo.Point; /** * @author Christoph Strobl * @author Mark Paluch + * @author Dennis Neufeld */ public interface ClusterConnectionTests { @@ -123,9 +124,39 @@ public interface ClusterConnectionTests { // DATAREDIS-315 void flushDbOnSingleNodeShouldFlushOnlyGivenNodesDb(); + // GH-2187 + void flushDbSyncOnSingleNodeShouldFlushOnlyGivenNodesDb(); + + // GH-2187 + void flushDbAsyncOnSingleNodeShouldFlushOnlyGivenNodesDb(); + // DATAREDIS-315 void flushDbShouldFlushAllClusterNodes(); + // GH-2187 + void flushDbSyncShouldFlushAllClusterNodes(); + + // GH-2187 + void flushDbAsyncShouldFlushAllClusterNodes(); + + // GH-2187 + void flushAllOnSingleNodeShouldFlushOnlyGivenNodesDb(); + + // GH-2187 + void flushAllSyncOnSingleNodeShouldFlushOnlyGivenNodesDb(); + + // GH-2187 + void flushAllAsyncOnSingleNodeShouldFlushOnlyGivenNodesDb(); + + // GH-2187 + void flushAllShouldFlushAllClusterNodes(); + + // GH-2187 + void flushAllSyncShouldFlushAllClusterNodes(); + + // GH-2187 + void flushAllAsyncShouldFlushAllClusterNodes(); + // DATAREDIS-438 void geoAddMultipleGeoLocations(); diff --git a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java index 55b0cb870..f94604039 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisConnectionUnitTests.java @@ -47,6 +47,7 @@ import org.springframework.util.ObjectUtils; * @author David Liu * @author Ninad Divadkar * @author Mark Paluch + * @author Dennis Neufeld */ class RedisConnectionUnitTests { @@ -433,6 +434,10 @@ class RedisConnectionUnitTests { delegate.flushDb(); } + public void flushDb(FlushOption option) { + delegate.flushDb(option); + } + public Boolean sIsMember(byte[] key, byte[] value) { return delegate.sIsMember(key, value); } @@ -457,6 +462,10 @@ class RedisConnectionUnitTests { delegate.flushAll(); } + public void flushAll(FlushOption option) { + delegate.flushAll(option); + } + public void lTrim(byte[] key, long begin, long end) { delegate.lTrim(key, begin, end); } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java index 818884293..3bf70eb6c 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java @@ -61,6 +61,7 @@ import org.springframework.data.redis.connection.RedisClusterNode; import org.springframework.data.redis.connection.RedisClusterNode.SlotRange; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; import org.springframework.data.redis.connection.RedisNode; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.connection.RedisStringCommands.BitOperation; import org.springframework.data.redis.connection.RedisStringCommands.SetOption; import org.springframework.data.redis.connection.ReturnType; @@ -79,6 +80,7 @@ import org.springframework.data.redis.test.util.HexStringUtils; * @author Christoph Strobl * @author Mark Paluch * @author Pavel Khokhlov + * @author Dennis Neufeld */ @EnabledOnRedisClusterAvailable @ExtendWith(JedisExtension.class) @@ -456,6 +458,30 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { assertThat(nativeConnection.get(KEY_2)).isNull(); } + @Test // GH-2187 + public void flushDbSyncOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), FlushOption.SYNC); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushDbAsyncOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), FlushOption.ASYNC); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + @Test // DATAREDIS-315 public void flushDbShouldFlushAllClusterNodes() { @@ -468,6 +494,102 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests { assertThat(nativeConnection.get(KEY_2)).isNull(); } + @Test // GH-2187 + public void flushDbSyncShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(FlushOption.SYNC); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushDbAsyncShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(FlushOption.ASYNC); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllSyncOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), FlushOption.SYNC); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllAsyncOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), FlushOption.ASYNC); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllSyncShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(FlushOption.SYNC); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllAsyncShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(FlushOption.ASYNC); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + @Test // DATAREDIS-438 public void geoAddMultipleGeoLocations() { assertThat(clusterConnection.geoAdd(KEY_1_BYTES, Arrays.asList(PALERMO, ARIGENTO, CATANIA, PALERMO))).isEqualTo(3L); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java index 72913a826..c0310d7fc 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java @@ -52,6 +52,7 @@ import org.springframework.data.redis.connection.*; import org.springframework.data.redis.connection.RedisClusterNode.SlotRange; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; import org.springframework.data.redis.connection.RedisListCommands.Position; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.connection.RedisStringCommands.BitOperation; import org.springframework.data.redis.connection.RedisStringCommands.SetOption; import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding; @@ -67,6 +68,7 @@ import org.springframework.data.redis.test.util.HexStringUtils; /** * @author Christoph Strobl * @author Mark Paluch + * @author Dennis Neufeld */ @SuppressWarnings("deprecation") @EnabledOnRedisClusterAvailable @@ -485,6 +487,30 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { assertThat(nativeConnection.get(KEY_2)).isNull(); } + @Test // GH-2187 + public void flushDbSyncOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), FlushOption.SYNC); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushDbAsyncOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), FlushOption.ASYNC); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + @Test // DATAREDIS-315 public void flushDbShouldFlushAllClusterNodes() { @@ -497,6 +523,102 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests { assertThat(nativeConnection.get(KEY_2)).isNull(); } + @Test // GH-2187 + public void flushDbSyncShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(FlushOption.SYNC); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushDbAsyncShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushDb(FlushOption.ASYNC); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty())); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllSyncOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), FlushOption.SYNC); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllAsyncOnSingleNodeShouldFlushOnlyGivenNodesDb() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), FlushOption.ASYNC); + + assertThat(nativeConnection.get(KEY_1)).isNotNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllSyncShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(FlushOption.SYNC); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + + @Test // GH-2187 + public void flushAllAsyncShouldFlushAllClusterNodes() { + + nativeConnection.set(KEY_1, VALUE_1); + nativeConnection.set(KEY_2, VALUE_2); + + clusterConnection.flushAll(FlushOption.ASYNC); + + assertThat(nativeConnection.get(KEY_1)).isNull(); + assertThat(nativeConnection.get(KEY_2)).isNull(); + } + @Test // DATAREDIS-438 public void geoAddMultipleGeoLocations() { assertThat(clusterConnection.geoAdd(KEY_1_BYTES, diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsIntegrationTests.java index 9d841245b..9ac157088 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsIntegrationTests.java @@ -23,10 +23,12 @@ import reactor.test.StepVerifier; import org.junit.jupiter.api.Test; import org.springframework.data.redis.connection.RedisClusterNode; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; /** * @author Mark Paluch * @author Christoph Strobl + * @author Dennis Neufeld */ class LettuceReactiveClusterServerCommandsIntegrationTests extends LettuceReactiveClusterTestSupport { @@ -72,6 +74,46 @@ class LettuceReactiveClusterServerCommandsIntegrationTests extends LettuceReacti connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); } + @Test // GH-2187 + void flushDbSyncShouldRespondCorrectly() { + + connection.serverCommands().flushDb() // + .then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)) // + .then(connection.stringCommands().set(KEY_2_BBUFFER, VALUE_2_BBUFFER)).as(StepVerifier::create) // + .expectNextCount(1) // + .verifyComplete(); + + connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNext(1L).verifyComplete(); + connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); + + connection.serverCommands().flushDb(NODE1, FlushOption.SYNC).as(StepVerifier::create) // + .expectNext("OK") // + .verifyComplete(); + + connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNext(0L).verifyComplete(); + connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); + } + + @Test // GH-2187 + void flushDbAsyncShouldRespondCorrectly() { + + connection.serverCommands().flushDb() // + .then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)) // + .then(connection.stringCommands().set(KEY_2_BBUFFER, VALUE_2_BBUFFER)).as(StepVerifier::create) // + .expectNextCount(1) // + .verifyComplete(); + + connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNext(1L).verifyComplete(); + connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); + + connection.serverCommands().flushDb(NODE1, FlushOption.ASYNC).as(StepVerifier::create) // + .expectNext("OK") // + .verifyComplete(); + + connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNext(0L).verifyComplete(); + connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); + } + @Test // DATAREDIS-659 void flushAllShouldRespondCorrectly() { @@ -90,6 +132,46 @@ class LettuceReactiveClusterServerCommandsIntegrationTests extends LettuceReacti connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); } + @Test // GH-2187 + void flushAllSyncShouldRespondCorrectly() { + + connection.serverCommands().flushAll() // + .then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)) // + .then(connection.stringCommands().set(KEY_2_BBUFFER, VALUE_2_BBUFFER)).as(StepVerifier::create) // + .expectNextCount(1) // + .verifyComplete(); + + connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNext(1L).verifyComplete(); + connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); + + connection.serverCommands().flushAll(NODE1, FlushOption.SYNC).as(StepVerifier::create) // + .expectNext("OK") // + .verifyComplete(); + + connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNext(0L).verifyComplete(); + connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); + } + + @Test // GH-2187 + void flushAllAsyncShouldRespondCorrectly() { + + connection.serverCommands().flushAll() // + .then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)) // + .then(connection.stringCommands().set(KEY_2_BBUFFER, VALUE_2_BBUFFER)).as(StepVerifier::create) // + .expectNextCount(1) // + .verifyComplete(); + + connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNext(1L).verifyComplete(); + connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); + + connection.serverCommands().flushAll(NODE1, FlushOption.ASYNC).as(StepVerifier::create) // + .expectNext("OK") // + .verifyComplete(); + + connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNext(0L).verifyComplete(); + connection.serverCommands().dbSize(NODE3).as(StepVerifier::create).expectNext(1L).verifyComplete(); + } + @Test // DATAREDIS-659 void infoShouldRespondCorrectly() { diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsIntegrationTests.java index 4dfdb9adb..5cc6180a7 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsIntegrationTests.java @@ -20,11 +20,14 @@ import static org.assertj.core.api.Assumptions.*; import reactor.test.StepVerifier; +import org.junit.jupiter.api.Disabled; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; /** * @author Mark Paluch * @author Christoph Strobl + * @author Dennis Neufeld */ public class LettuceReactiveServerCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport { @@ -70,6 +73,42 @@ public class LettuceReactiveServerCommandsIntegrationTests extends LettuceReacti connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(0L).verifyComplete(); } + @Disabled("Wait for https://github.com/lettuce-io/lettuce-core/pull/1908") + @ParameterizedRedisTest // GH-2187 + void flushDbSyncShouldRespondCorrectly() { + + connection.serverCommands().flushDb() // + .then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)).as(StepVerifier::create) // + .expectNextCount(1) // + .verifyComplete(); + + connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(1L).verifyComplete(); + + connection.serverCommands().flushDb(FlushOption.SYNC).as(StepVerifier::create) // + .expectNext("OK") // + .verifyComplete(); + + connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(0L).verifyComplete(); + } + + @Disabled("Wait for https://github.com/lettuce-io/lettuce-core/pull/1908") + @ParameterizedRedisTest // GH-2187 + void flushDbAsyncShouldRespondCorrectly() { + + connection.serverCommands().flushDb() // + .then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)).as(StepVerifier::create) // + .expectNextCount(1) // + .verifyComplete(); + + connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(1L).verifyComplete(); + + connection.serverCommands().flushDb(FlushOption.ASYNC).as(StepVerifier::create) // + .expectNext("OK") // + .verifyComplete(); + + connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(0L).verifyComplete(); + } + @ParameterizedRedisTest // DATAREDIS-659 void flushAllShouldRespondCorrectly() { @@ -85,6 +124,38 @@ public class LettuceReactiveServerCommandsIntegrationTests extends LettuceReacti connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(0L).verifyComplete(); } + @Disabled("Wait for https://github.com/lettuce-io/lettuce-core/pull/1908") + @ParameterizedRedisTest // GH-2187 + void flushAllSyncShouldRespondCorrectly() { + + connection.serverCommands().flushAll() // + .then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)).as(StepVerifier::create) // + .expectNextCount(1) // + .verifyComplete(); + + connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(1L).verifyComplete(); + + connection.serverCommands().flushAll(FlushOption.SYNC).as(StepVerifier::create).expectNext("OK").verifyComplete(); + + connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(0L).verifyComplete(); + } + + @Disabled("Wait for https://github.com/lettuce-io/lettuce-core/pull/1908") + @ParameterizedRedisTest // GH-2187 + void flushAllAsyncShouldRespondCorrectly() { + + connection.serverCommands().flushAll() // + .then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)).as(StepVerifier::create) // + .expectNextCount(1) // + .verifyComplete(); + + connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(1L).verifyComplete(); + + connection.serverCommands().flushAll(FlushOption.ASYNC).as(StepVerifier::create).expectNext("OK").verifyComplete(); + + connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(0L).verifyComplete(); + } + @ParameterizedRedisTest // DATAREDIS-659 void infoShouldRespondCorrectly() { diff --git a/src/test/java/org/springframework/data/redis/core/DefaultClusterOperationsUnitTests.java b/src/test/java/org/springframework/data/redis/core/DefaultClusterOperationsUnitTests.java index 97dc03c84..880ea6157 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultClusterOperationsUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultClusterOperationsUnitTests.java @@ -37,6 +37,7 @@ import org.springframework.data.redis.connection.RedisClusterConnection; import org.springframework.data.redis.connection.RedisClusterNode; import org.springframework.data.redis.connection.RedisClusterNode.SlotRange; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisServerCommands.FlushOption; import org.springframework.data.redis.connection.RedisServerCommands.MigrateOption; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; @@ -44,6 +45,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; /** * @author Christoph Strobl * @author Mark Paluch + * @author Dennis Neufeld */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) @@ -208,6 +210,22 @@ class DefaultClusterOperationsUnitTests { verify(connection, times(1)).flushDb(eq(NODE_1)); } + @Test // GH-2187 + void flushDbSyncShouldDelegateToConnection() { + + clusterOps.flushDb(NODE_1, FlushOption.SYNC); + + verify(connection, times(1)).flushDb(eq(NODE_1), eq(FlushOption.SYNC)); + } + + @Test // GH-2187 + void flushDbAsyncShouldDelegateToConnection() { + + clusterOps.flushDb(NODE_1, FlushOption.ASYNC); + + verify(connection, times(1)).flushDb(eq(NODE_1), eq(FlushOption.ASYNC)); + } + @Test // DATAREDIS-315 void flushDbShouldThrowExceptionWhenNodeIsNull() { assertThatIllegalArgumentException().isThrownBy(() -> clusterOps.flushDb(null));