Add support for flush modes using FLUSHDB and FLUSHALL commands.

Closes #2187
Original pull request: #2190.
This commit is contained in:
Napster
2021-11-02 23:58:56 +01:00
committed by Mark Paluch
parent a0b70a346c
commit 3879a5a80d
22 changed files with 813 additions and 0 deletions

View File

@@ -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 {
@@ -401,6 +402,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
delegate.flushAll();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushAll(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushAll(FlushOption option) {
delegate.flushAll(option);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushDb()
@@ -410,6 +420,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
delegate.flushDb();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushDb(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushDb(FlushOption option) {
delegate.flushDb(option);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisStringCommands#get(byte[])

View File

@@ -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

View File

@@ -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

View File

@@ -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<String> 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<String> flushDb(RedisClusterNode node, FlushOption option);
/**
* Delete all <b>all keys</b> from <b>all databases</b>.
*
@@ -101,6 +114,18 @@ public interface ReactiveClusterServerCommands extends ReactiveServerCommands {
*/
Mono<String> flushAll(RedisClusterNode node);
/**
* Delete all <b>all keys</b> from <b>all databases</b> 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<String> flushAll(RedisClusterNode node, FlushOption option);
/**
* Load {@literal default} server information like
* <ul>

View File

@@ -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<String> flushDb();
/**
* Delete all keys of the currently selected database using the specified flush option.
*
* @param option
* @return {@link Mono} indicating command completion.
* @see <a href="https://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
* @since 2.6
*/
Mono<String> flushDb(FlushOption option);
/**
* Delete all <b>all keys</b> from <b>all databases</b>.
*
@@ -89,6 +101,16 @@ public interface ReactiveServerCommands {
*/
Mono<String> flushAll();
/**
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
*
* @param option
* @return {@link Mono} indicating command completion.
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
* @since 2.6
*/
Mono<String> flushAll(FlushOption option);
/**
* Load {@literal default} server information like
* <ul>

View File

@@ -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

View File

@@ -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 <a href="https://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
* @since 2.6
*/
void flushDb(FlushOption option);
/**
* Delete all <b>all keys</b> from <b>all databases</b>.
*
@@ -108,6 +125,15 @@ public interface RedisServerCommands {
*/
void flushAll();
/**
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
*
* @param option
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
* @since 2.6
*/
void flushAll(FlushOption option);
/**
* Load {@literal default} server information like
* <ul>

View File

@@ -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 {
@@ -171,6 +173,15 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
executeCommandOnAllNodes(BinaryJedis::flushDB);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushDb(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushDb(FlushOption option) {
executeCommandOnAllNodes(it -> it.flushDB(toFlushMode(option)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#flushDb(org.springframework.data.redis.connection.RedisClusterNode)
@@ -180,6 +191,15 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
executeCommandOnSingleNode(BinaryJedis::flushDB, node);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#flushDb(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushDb(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushDB(toFlushMode(option)), node);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushAll()
@@ -190,6 +210,16 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
.executeCommandOnAllNodes((JedisClusterCommandCallback<String>) BinaryJedis::flushAll);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushAll(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushAll(FlushOption option) {
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback<String>) it -> it.flushAll(toFlushMode(option)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#flushAll(org.springframework.data.redis.connection.RedisClusterNode)
@@ -199,6 +229,15 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
executeCommandOnSingleNode(BinaryJedis::flushAll, node);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#flushAll(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushAll(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushAll(toFlushMode(option)), node);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#info()
@@ -555,4 +594,19 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
private <T> MultiNodeResult<T> executeCommandOnAllNodes(JedisClusterCommandCallback<T> 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.");
}
}

View File

@@ -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 {
@@ -99,6 +101,17 @@ class JedisServerCommands implements RedisServerCommands {
connection.invokeStatus().just(BinaryJedis::flushDB, MultiKeyPipelineBase::flushDB);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushDb(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushDb(FlushOption option) {
FlushMode flushMode = JedisClusterServerCommands.toFlushMode(option);
connection.invokeStatus().just(it -> it.flushDB(flushMode), it -> it.flushDB(flushMode));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushAll()
@@ -108,6 +121,17 @@ class JedisServerCommands implements RedisServerCommands {
connection.invokeStatus().just(BinaryJedis::flushAll, MultiKeyPipelineBase::flushAll);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushAll(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushAll(FlushOption option) {
FlushMode flushMode = JedisClusterServerCommands.toFlushMode(option);
connection.invokeStatus().just(it -> it.flushAll(flushMode), it -> it.flushAll(flushMode));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#info()

View File

@@ -38,6 +38,7 @@ import org.springframework.util.CollectionUtils;
/**
* @author Mark Paluch
* @author Dennis Neufeld
* @since 2.0
*/
class LettuceClusterServerCommands extends LettuceServerCommands implements RedisClusterServerCommands {
@@ -124,6 +125,15 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
executeCommandOnAllNodes(RedisServerCommands::flushdb);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceServerCommands#flushDb(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushDb(FlushOption option) {
executeCommandOnAllNodes(it -> it.flushdb(toFlushMode(option)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#flushDb(org.springframework.data.redis.connection.RedisClusterNode)
@@ -133,6 +143,15 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
executeCommandOnSingleNode(RedisServerCommands::flushdb, node);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#flushDb(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushDb(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushdb(toFlushMode(option)), node);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceServerCommands#flushAll()
@@ -142,6 +161,15 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
executeCommandOnAllNodes(RedisServerCommands::flushall);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceServerCommands#flushAll(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushAll(FlushOption option) {
executeCommandOnAllNodes(it -> it.flushall(toFlushMode(option)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#flushAll(org.springframework.data.redis.connection.RedisClusterNode)
@@ -151,6 +179,15 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
executeCommandOnSingleNode(RedisServerCommands::flushall, node);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#flushAll(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushAll(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushall(toFlushMode(option)), node);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisClusterServerCommands#info(org.springframework.data.redis.connection.RedisClusterNode)

View File

@@ -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
@@ -129,6 +131,15 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
return connection.execute(node, RedisServerReactiveCommands::flushdb).next();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveClusterServerCommands#flushDb(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public Mono<String> flushDb(RedisClusterNode node, FlushOption option) {
return connection.execute(node, it -> it.flushdb(LettuceServerCommands.toFlushMode(option))).next();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveClusterServerCommands#flushAll(org.springframework.data.redis.connection.RedisClusterNode)
@@ -138,6 +149,15 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
return connection.execute(node, RedisServerReactiveCommands::flushall).next();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveClusterServerCommands#flushAll(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public Mono<String> flushAll(RedisClusterNode node, FlushOption option) {
return connection.execute(node, it -> it.flushall(LettuceServerCommands.toFlushMode(option))).next();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.lettuce.LettuceReactiveServerCommands#info()

View File

@@ -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 {
@@ -106,6 +108,15 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
return connection.execute(RedisServerReactiveCommands::flushdb).next();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveServerCommands#flushDb(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public Mono<String> flushDb(FlushOption option) {
return connection.execute(it -> it.flushdb(LettuceServerCommands.toFlushMode(option))).next();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveServerCommands#flushAll()
@@ -115,6 +126,15 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
return connection.execute(RedisServerReactiveCommands::flushall).next();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveServerCommands#flushAll(FlushOption)
*/
@Override
public Mono<String> flushAll(FlushOption option) {
return connection.execute(it -> it.flushall(LettuceServerCommands.toFlushMode(option))).next();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.ReactiveServerCommands#info()

View File

@@ -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 {
@@ -98,6 +100,15 @@ class LettuceServerCommands implements RedisServerCommands {
connection.invokeStatus().just(RedisServerAsyncCommands::flushdb);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushDb(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushDb(FlushOption option) {
connection.invoke().just(it -> it.flushdb(toFlushMode(option)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushAll()
@@ -107,6 +118,15 @@ class LettuceServerCommands implements RedisServerCommands {
connection.invokeStatus().just(RedisServerAsyncCommands::flushall);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#flushAll(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushAll(FlushOption option) {
connection.invokeStatus().just(it -> it.flushall(toFlushMode(option)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisServerCommands#info()
@@ -317,6 +337,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<T> extends CompletableFuture<T> implements RedisFuture<T> {
public CompletedRedisFuture(T value) {

View File

@@ -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<K, V> {
@@ -117,6 +119,16 @@ public interface ClusterOperations<K, V> {
*/
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

View File

@@ -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 <K>
* @param <V>
@@ -189,6 +191,21 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
});
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ClusterOperations#flushDb(org.springframework.data.redis.connection.RedisClusterNode, org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
*/
@Override
public void flushDb(RedisClusterNode node, FlushOption option) {
Assert.notNull(node, "ClusterNode must not be null.");
doInCluster((RedisClusterCallback<Void>) connection -> {
connection.flushDb(node, option);
return null;
});
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.RedisClusterOperations#getSlaves(org.springframework.data.redis.connection.RedisClusterNode)

View File

@@ -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();

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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,

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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));