Polishing.

Update since tags. Move FlushOption converters to client-specific converters. Use method-references where possible.

See #2187
Original pull request: #2190.
This commit is contained in:
Mark Paluch
2022-03-10 10:43:30 +01:00
parent 3191def956
commit f19a61452a
15 changed files with 96 additions and 99 deletions

View File

@@ -94,13 +94,13 @@ public interface ReactiveClusterServerCommands extends ReactiveServerCommands {
Mono<String> flushDb(RedisClusterNode node);
/**
* Delete all keys of the currently selected database using the specified flush option.
* Delete all keys of the currently selected database using the specified {@link FlushOption}.
*
* @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
* @since 2.7
*/
Mono<String> flushDb(RedisClusterNode node, FlushOption option);
@@ -115,14 +115,14 @@ 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.
* Delete all <b>all keys</b> from <b>all databases</b> using the specified {@link FlushOption}.
*
* @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
* @since 2.7
*/
Mono<String> flushAll(RedisClusterNode node, FlushOption option);

View File

@@ -84,12 +84,12 @@ public interface ReactiveServerCommands {
Mono<String> flushDb();
/**
* Delete all keys of the currently selected database using the specified flush option.
* Delete all keys of the currently selected database using the specified {@link FlushOption}.
*
* @param option
* @return {@link Mono} indicating command completion.
* @see <a href="https://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
* @since 2.6
* @since 2.7
*/
Mono<String> flushDb(FlushOption option);
@@ -102,12 +102,12 @@ public interface ReactiveServerCommands {
Mono<String> flushAll();
/**
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
* Delete all <b>all keys</b> from <b>all databases</b> using the specified {@link FlushOption}.
*
* @param option
* @return {@link Mono} indicating command completion.
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
* @since 2.6
* @since 2.7
*/
Mono<String> flushAll(FlushOption option);

View File

@@ -70,7 +70,7 @@ public interface RedisClusterServerCommands extends RedisServerCommands {
* @param node must not be {@literal null}.
* @param option
* @see RedisServerCommands#flushDb(FlushOption)
* @since 2.6
* @since 2.7
*/
void flushDb(RedisClusterNode node, FlushOption option);
@@ -84,7 +84,7 @@ public interface RedisClusterServerCommands extends RedisServerCommands {
* @param node must not be {@literal null}.
* @param option
* @see RedisServerCommands#flushAll(FlushOption)
* @since 2.6
* @since 2.7
*/
void flushAll(RedisClusterNode node, FlushOption option);

View File

@@ -45,7 +45,7 @@ public interface RedisServerCommands {
}
/**
* @since 2.6
* @since 2.7
*/
enum FlushOption {
SYNC, ASYNC
@@ -110,11 +110,11 @@ public interface RedisServerCommands {
void flushDb();
/**
* Delete all keys of the currently selected database using the specified flush option.
* Delete all keys of the currently selected database using the specified {@link FlushOption}.
*
* @param option
* @see <a href="https://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
* @since 2.6
* @since 2.7
*/
void flushDb(FlushOption option);
@@ -126,11 +126,11 @@ public interface RedisServerCommands {
void flushAll();
/**
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
* Delete all <b>all keys</b> from <b>all databases</b> using the specified {@link FlushOption}.
*
* @param option
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
* @since 2.6
* @since 2.7
*/
void flushAll(FlushOption option);

View File

@@ -17,7 +17,6 @@ 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;
@@ -131,7 +130,7 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
@Override
public void flushDb(FlushOption option) {
executeCommandOnAllNodes(it -> it.flushDB(toFlushMode(option)));
executeCommandOnAllNodes(it -> it.flushDB(JedisConverters.toFlushMode(option)));
}
@Override
@@ -141,7 +140,7 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
@Override
public void flushDb(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushDB(toFlushMode(option)), node);
executeCommandOnSingleNode(it -> it.flushDB(JedisConverters.toFlushMode(option)), node);
}
@Override
@@ -153,7 +152,8 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
@Override
public void flushAll(FlushOption option) {
connection.getClusterCommandExecutor()
.executeCommandOnAllNodes((JedisClusterCommandCallback<String>) it -> it.flushAll(toFlushMode(option)));
.executeCommandOnAllNodes(
(JedisClusterCommandCallback<String>) it -> it.flushAll(JedisConverters.toFlushMode(option)));
}
@Override
@@ -163,7 +163,7 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
@Override
public void flushAll(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushAll(toFlushMode(option)), node);
executeCommandOnSingleNode(it -> it.flushAll(JedisConverters.toFlushMode(option)), node);
}
@Override
@@ -319,16 +319,18 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
@Override
public Long time(TimeUnit timeUnit) {
return convertListOfStringToTime(connection.getClusterCommandExecutor()
.executeCommandOnArbitraryNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time).getValue(),
return convertListOfStringToTime(
connection.getClusterCommandExecutor()
.executeCommandOnArbitraryNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time).getValue(),
timeUnit);
}
@Override
public Long time(RedisClusterNode node, TimeUnit timeUnit) {
return convertListOfStringToTime(connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time, node).getValue(),
return convertListOfStringToTime(
connection.getClusterCommandExecutor()
.executeCommandOnSingleNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time, node).getValue(),
timeUnit);
}
@@ -419,18 +421,4 @@ class JedisClusterServerCommands implements RedisClusterServerCommands {
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

@@ -22,6 +22,7 @@ import redis.clients.jedis.GeoUnit;
import redis.clients.jedis.ListPosition;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.SetParams;
@@ -59,6 +60,7 @@ import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusComma
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.Flag;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.RedisServerCommands;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundary;
@@ -436,10 +438,12 @@ public abstract class JedisConverters extends Converters {
}
if (expiration.getTimeUnit() == TimeUnit.MILLISECONDS) {
return expiration.isUnixTimestamp() ? paramsToUse.pxAt(expiration.getExpirationTime()) : paramsToUse.px(expiration.getExpirationTime());
return expiration.isUnixTimestamp() ? paramsToUse.pxAt(expiration.getExpirationTime())
: paramsToUse.px(expiration.getExpirationTime());
}
return expiration.isUnixTimestamp() ? paramsToUse.exAt(expiration.getConverted(TimeUnit.SECONDS)) : paramsToUse.ex(expiration.getConverted(TimeUnit.SECONDS));
return expiration.isUnixTimestamp() ? paramsToUse.exAt(expiration.getConverted(TimeUnit.SECONDS))
: paramsToUse.ex(expiration.getConverted(TimeUnit.SECONDS));
}
/**
@@ -814,6 +818,22 @@ public abstract class JedisConverters extends Converters {
return args.toArray(new byte[0][0]);
}
static FlushMode toFlushMode(@Nullable RedisServerCommands.FlushOption option) {
if (option == null) {
return FlushMode.SYNC;
}
switch (option) {
case ASYNC:
return FlushMode.ASYNC;
case SYNC:
return FlushMode.SYNC;
default:
throw new IllegalArgumentException("Flush option " + option + " is not supported.");
}
}
/**
* @author Christoph Strobl
* @since 1.8

View File

@@ -18,7 +18,6 @@ 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;
@@ -39,8 +38,6 @@ import org.springframework.util.Assert;
*/
class JedisServerCommands implements RedisServerCommands {
private static final String SHUTDOWN_SCRIPT = "return redis.call('SHUTDOWN','%s')";
private final JedisConnection connection;
JedisServerCommands(JedisConnection connection) {
@@ -79,9 +76,8 @@ class JedisServerCommands implements RedisServerCommands {
@Override
public void flushDb(FlushOption option) {
FlushMode flushMode = JedisClusterServerCommands.toFlushMode(option);
connection.invokeStatus().just(it -> it.flushDB(flushMode), it -> it.flushDB(flushMode));
connection.invokeStatus().just(BinaryJedis::flushDB, MultiKeyPipelineBase::flushDB,
JedisConverters.toFlushMode(option));
}
@Override
@@ -91,9 +87,8 @@ class JedisServerCommands implements RedisServerCommands {
@Override
public void flushAll(FlushOption option) {
FlushMode flushMode = JedisClusterServerCommands.toFlushMode(option);
connection.invokeStatus().just(it -> it.flushAll(flushMode), it -> it.flushAll(flushMode));
connection.invokeStatus().just(BinaryJedis::flushAll, MultiKeyPipelineBase::flushAll,
JedisConverters.toFlushMode(option));
}
@Override

View File

@@ -99,7 +99,7 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
@Override
public void flushDb(FlushOption option) {
executeCommandOnAllNodes(it -> it.flushdb(toFlushMode(option)));
executeCommandOnAllNodes(it -> it.flushdb(LettuceConverters.toFlushMode(option)));
}
@Override
@@ -109,7 +109,7 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
@Override
public void flushDb(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushdb(toFlushMode(option)), node);
executeCommandOnSingleNode(it -> it.flushdb(LettuceConverters.toFlushMode(option)), node);
}
@Override
@@ -119,7 +119,7 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
@Override
public void flushAll(FlushOption option) {
executeCommandOnAllNodes(it -> it.flushall(toFlushMode(option)));
executeCommandOnAllNodes(it -> it.flushall(LettuceConverters.toFlushMode(option)));
}
@Override
@@ -129,7 +129,7 @@ class LettuceClusterServerCommands extends LettuceServerCommands implements Redi
@Override
public void flushAll(RedisClusterNode node, FlushOption option) {
executeCommandOnSingleNode(it -> it.flushall(toFlushMode(option)), node);
executeCommandOnSingleNode(it -> it.flushall(LettuceConverters.toFlushMode(option)), node);
}
@Override

View File

@@ -896,10 +896,9 @@ public abstract class LettuceConverters extends Converters {
if (args.hasFlags()) {
for (GeoCommandArgs.GeoCommandFlag flag : args.getFlags()) {
if(flag.equals(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
if (flag.equals(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
geoArgs.withCoordinates();
}
else if(flag.equals(GeoRadiusCommandArgs.Flag.WITHDIST)) {
} else if (flag.equals(GeoRadiusCommandArgs.Flag.WITHDIST)) {
geoArgs.withDistance();
}
}
@@ -1171,6 +1170,22 @@ public abstract class LettuceConverters extends Converters {
throw new IllegalArgumentException(String.format("Cannot convert %s to Lettuce GeoRef", reference));
}
static FlushMode toFlushMode(@Nullable RedisServerCommands.FlushOption option) {
if (option == null) {
return FlushMode.SYNC;
}
switch (option) {
case ASYNC:
return FlushMode.ASYNC;
case SYNC:
return FlushMode.SYNC;
default:
throw new IllegalArgumentException("Flush option " + option + " is not supported.");
}
}
/**
* @author Christoph Strobl
* @since 1.8

View File

@@ -109,7 +109,7 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
@Override
public Mono<String> flushDb(RedisClusterNode node, FlushOption option) {
return connection.execute(node, it -> it.flushdb(LettuceServerCommands.toFlushMode(option))).next();
return connection.execute(node, it -> it.flushdb(LettuceConverters.toFlushMode(option))).next();
}
@Override
@@ -119,7 +119,7 @@ class LettuceReactiveClusterServerCommands extends LettuceReactiveServerCommands
@Override
public Mono<String> flushAll(RedisClusterNode node, FlushOption option) {
return connection.execute(node, it -> it.flushall(LettuceServerCommands.toFlushMode(option))).next();
return connection.execute(node, it -> it.flushall(LettuceConverters.toFlushMode(option))).next();
}
@Override

View File

@@ -86,7 +86,7 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
@Override
public Mono<String> flushDb(FlushOption option) {
return connection.execute(it -> it.flushdb(LettuceServerCommands.toFlushMode(option))).next();
return connection.execute(it -> it.flushdb(LettuceConverters.toFlushMode(option))).next();
}
@Override
@@ -96,7 +96,7 @@ class LettuceReactiveServerCommands implements ReactiveServerCommands {
@Override
public Mono<String> flushAll(FlushOption option) {
return connection.execute(it -> it.flushall(LettuceServerCommands.toFlushMode(option))).next();
return connection.execute(it -> it.flushall(LettuceConverters.toFlushMode(option))).next();
}
@Override

View File

@@ -15,7 +15,6 @@
*/
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;
@@ -78,7 +77,7 @@ class LettuceServerCommands implements RedisServerCommands {
@Override
public void flushDb(FlushOption option) {
connection.invoke().just(it -> it.flushdb(toFlushMode(option)));
connection.invokeStatus().just(RedisServerAsyncCommands::flushdb, LettuceConverters.toFlushMode(option));
}
@Override
@@ -88,7 +87,7 @@ class LettuceServerCommands implements RedisServerCommands {
@Override
public void flushAll(FlushOption option) {
connection.invokeStatus().just(it -> it.flushall(toFlushMode(option)));
connection.invokeStatus().just(RedisServerAsyncCommands::flushall, LettuceConverters.toFlushMode(option));
}
@Override
@@ -233,21 +232,6 @@ 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

@@ -120,12 +120,12 @@ public interface ClusterOperations<K, V> {
void flushDb(RedisClusterNode node);
/**
* Flush db on node using the specified flush option.
* Flush db on node using the specified {@link FlushOption}.
*
* @param node must not be {@literal null}.
* @param option
* @param option must not be {@literal null}.
* @see RedisConnection#flushDb(FlushOption)
* @since 2.6
* @since 2.7
*/
void flushDb(RedisClusterNode node, FlushOption option);

View File

@@ -53,7 +53,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public Set<K> keys(final RedisClusterNode node, final K pattern) {
public Set<K> keys(RedisClusterNode node, K pattern) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -61,7 +61,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public K randomKey(final RedisClusterNode node) {
public K randomKey(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -69,7 +69,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public String ping(final RedisClusterNode node) {
public String ping(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -77,7 +77,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void addSlots(final RedisClusterNode node, final int... slots) {
public void addSlots(RedisClusterNode node, int... slots) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -97,7 +97,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void bgReWriteAof(final RedisClusterNode node) {
public void bgReWriteAof(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -108,7 +108,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void bgSave(final RedisClusterNode node) {
public void bgSave(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -119,7 +119,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void meet(final RedisClusterNode node) {
public void meet(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -130,7 +130,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void forget(final RedisClusterNode node) {
public void forget(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -141,7 +141,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void flushDb(final RedisClusterNode node) {
public void flushDb(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -163,7 +163,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public Collection<RedisClusterNode> getSlaves(final RedisClusterNode node) {
public Collection<RedisClusterNode> getSlaves(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -171,7 +171,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void save(final RedisClusterNode node) {
public void save(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -182,7 +182,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void shutdown(final RedisClusterNode node) {
public void shutdown(RedisClusterNode node) {
Assert.notNull(node, "ClusterNode must not be null.");
@@ -193,7 +193,7 @@ class DefaultClusterOperations<K, V> extends AbstractOperations<K, V> implements
}
@Override
public void reshard(final RedisClusterNode source, final int slot, final RedisClusterNode target) {
public void reshard(RedisClusterNode source, int slot, RedisClusterNode target) {
Assert.notNull(source, "Source node must not be null.");
Assert.notNull(target, "Target node must not be null.");