Skip to content

Commit f19a614

Browse files
committed
Polishing.
Update since tags. Move FlushOption converters to client-specific converters. Use method-references where possible. See #2187 Original pull request: #2190.
1 parent 3191def commit f19a614

15 files changed

+96
-99
lines changed

src/main/java/org/springframework/data/redis/connection/ReactiveClusterServerCommands.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public interface ReactiveClusterServerCommands extends ReactiveServerCommands {
9494
Mono<String> flushDb(RedisClusterNode node);
9595

9696
/**
97-
* Delete all keys of the currently selected database using the specified flush option.
97+
* Delete all keys of the currently selected database using the specified {@link FlushOption}.
9898
*
9999
* @param node must not be {@literal null}. {@link Mono} indicating command completion.
100100
* @param option
101101
* @throws IllegalArgumentException when {@code node} is {@literal null}.
102102
* @see RedisServerCommands#flushDb(FlushOption)
103-
* @since 2.6
103+
* @since 2.7
104104
*/
105105
Mono<String> flushDb(RedisClusterNode node, FlushOption option);
106106

@@ -115,14 +115,14 @@ public interface ReactiveClusterServerCommands extends ReactiveServerCommands {
115115
Mono<String> flushAll(RedisClusterNode node);
116116

117117
/**
118-
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
118+
* Delete all <b>all keys</b> from <b>all databases</b> using the specified {@link FlushOption}.
119119
*
120120
* @param node must not be {@literal null}.
121121
* @param option
122122
* @return {@link Mono} indicating command completion.
123123
* @throws IllegalArgumentException when {@code node} is {@literal null}.
124124
* @see RedisServerCommands#flushAll(FlushOption)
125-
* @since 2.6
125+
* @since 2.7
126126
*/
127127
Mono<String> flushAll(RedisClusterNode node, FlushOption option);
128128

src/main/java/org/springframework/data/redis/connection/ReactiveServerCommands.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ public interface ReactiveServerCommands {
8484
Mono<String> flushDb();
8585

8686
/**
87-
* Delete all keys of the currently selected database using the specified flush option.
87+
* Delete all keys of the currently selected database using the specified {@link FlushOption}.
8888
*
8989
* @param option
9090
* @return {@link Mono} indicating command completion.
9191
* @see <a href="https://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
92-
* @since 2.6
92+
* @since 2.7
9393
*/
9494
Mono<String> flushDb(FlushOption option);
9595

@@ -102,12 +102,12 @@ public interface ReactiveServerCommands {
102102
Mono<String> flushAll();
103103

104104
/**
105-
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
105+
* Delete all <b>all keys</b> from <b>all databases</b> using the specified {@link FlushOption}.
106106
*
107107
* @param option
108108
* @return {@link Mono} indicating command completion.
109109
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
110-
* @since 2.6
110+
* @since 2.7
111111
*/
112112
Mono<String> flushAll(FlushOption option);
113113

src/main/java/org/springframework/data/redis/connection/RedisClusterServerCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface RedisClusterServerCommands extends RedisServerCommands {
7070
* @param node must not be {@literal null}.
7171
* @param option
7272
* @see RedisServerCommands#flushDb(FlushOption)
73-
* @since 2.6
73+
* @since 2.7
7474
*/
7575
void flushDb(RedisClusterNode node, FlushOption option);
7676

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

src/main/java/org/springframework/data/redis/connection/RedisServerCommands.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum MigrateOption {
4545
}
4646

4747
/**
48-
* @since 2.6
48+
* @since 2.7
4949
*/
5050
enum FlushOption {
5151
SYNC, ASYNC
@@ -110,11 +110,11 @@ default void bgWriteAof() {
110110
void flushDb();
111111

112112
/**
113-
* Delete all keys of the currently selected database using the specified flush option.
113+
* Delete all keys of the currently selected database using the specified {@link FlushOption}.
114114
*
115115
* @param option
116116
* @see <a href="https://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
117-
* @since 2.6
117+
* @since 2.7
118118
*/
119119
void flushDb(FlushOption option);
120120

@@ -126,11 +126,11 @@ default void bgWriteAof() {
126126
void flushAll();
127127

128128
/**
129-
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
129+
* Delete all <b>all keys</b> from <b>all databases</b> using the specified {@link FlushOption}.
130130
*
131131
* @param option
132132
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
133-
* @since 2.6
133+
* @since 2.7
134134
*/
135135
void flushAll(FlushOption option);
136136

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterServerCommands.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import redis.clients.jedis.BinaryJedis;
1919
import redis.clients.jedis.Jedis;
20-
import redis.clients.jedis.args.FlushMode;
2120

2221
import java.util.ArrayList;
2322
import java.util.Collection;
@@ -131,7 +130,7 @@ public void flushDb() {
131130

132131
@Override
133132
public void flushDb(FlushOption option) {
134-
executeCommandOnAllNodes(it -> it.flushDB(toFlushMode(option)));
133+
executeCommandOnAllNodes(it -> it.flushDB(JedisConverters.toFlushMode(option)));
135134
}
136135

137136
@Override
@@ -141,7 +140,7 @@ public void flushDb(RedisClusterNode node) {
141140

142141
@Override
143142
public void flushDb(RedisClusterNode node, FlushOption option) {
144-
executeCommandOnSingleNode(it -> it.flushDB(toFlushMode(option)), node);
143+
executeCommandOnSingleNode(it -> it.flushDB(JedisConverters.toFlushMode(option)), node);
145144
}
146145

147146
@Override
@@ -153,7 +152,8 @@ public void flushAll() {
153152
@Override
154153
public void flushAll(FlushOption option) {
155154
connection.getClusterCommandExecutor()
156-
.executeCommandOnAllNodes((JedisClusterCommandCallback<String>) it -> it.flushAll(toFlushMode(option)));
155+
.executeCommandOnAllNodes(
156+
(JedisClusterCommandCallback<String>) it -> it.flushAll(JedisConverters.toFlushMode(option)));
157157
}
158158

159159
@Override
@@ -163,7 +163,7 @@ public void flushAll(RedisClusterNode node) {
163163

164164
@Override
165165
public void flushAll(RedisClusterNode node, FlushOption option) {
166-
executeCommandOnSingleNode(it -> it.flushAll(toFlushMode(option)), node);
166+
executeCommandOnSingleNode(it -> it.flushAll(JedisConverters.toFlushMode(option)), node);
167167
}
168168

169169
@Override
@@ -319,16 +319,18 @@ public void rewriteConfig(RedisClusterNode node) {
319319
@Override
320320
public Long time(TimeUnit timeUnit) {
321321

322-
return convertListOfStringToTime(connection.getClusterCommandExecutor()
323-
.executeCommandOnArbitraryNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time).getValue(),
322+
return convertListOfStringToTime(
323+
connection.getClusterCommandExecutor()
324+
.executeCommandOnArbitraryNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time).getValue(),
324325
timeUnit);
325326
}
326327

327328
@Override
328329
public Long time(RedisClusterNode node, TimeUnit timeUnit) {
329330

330-
return convertListOfStringToTime(connection.getClusterCommandExecutor()
331-
.executeCommandOnSingleNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time, node).getValue(),
331+
return convertListOfStringToTime(
332+
connection.getClusterCommandExecutor()
333+
.executeCommandOnSingleNode((JedisClusterCommandCallback<List<String>>) BinaryJedis::time, node).getValue(),
332334
timeUnit);
333335
}
334336

@@ -419,18 +421,4 @@ private <T> MultiNodeResult<T> executeCommandOnAllNodes(JedisClusterCommandCallb
419421
return connection.getClusterCommandExecutor().executeCommandOnAllNodes(cmd);
420422
}
421423

422-
static FlushMode toFlushMode(@Nullable FlushOption option) {
423-
424-
if (option == null) {
425-
return FlushMode.SYNC;
426-
}
427-
428-
switch (option) {
429-
case ASYNC:
430-
return FlushMode.ASYNC;
431-
case SYNC:
432-
return FlushMode.SYNC;
433-
}
434-
throw new UnsupportedOperationException("Flush option " + option + " is not implemented.");
435-
}
436424
}

src/main/java/org/springframework/data/redis/connection/jedis/JedisConverters.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import redis.clients.jedis.ListPosition;
2323
import redis.clients.jedis.ScanParams;
2424
import redis.clients.jedis.SortingParams;
25+
import redis.clients.jedis.args.FlushMode;
2526
import redis.clients.jedis.params.GeoRadiusParam;
2627
import redis.clients.jedis.params.GetExParams;
2728
import redis.clients.jedis.params.SetParams;
@@ -59,6 +60,7 @@
5960
import org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.Flag;
6061
import org.springframework.data.redis.connection.RedisListCommands.Position;
6162
import org.springframework.data.redis.connection.RedisServer;
63+
import org.springframework.data.redis.connection.RedisServerCommands;
6264
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
6365
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
6466
import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundary;
@@ -436,10 +438,12 @@ public static SetParams toSetCommandExPxArgument(Expiration expiration, SetParam
436438
}
437439

438440
if (expiration.getTimeUnit() == TimeUnit.MILLISECONDS) {
439-
return expiration.isUnixTimestamp() ? paramsToUse.pxAt(expiration.getExpirationTime()) : paramsToUse.px(expiration.getExpirationTime());
441+
return expiration.isUnixTimestamp() ? paramsToUse.pxAt(expiration.getExpirationTime())
442+
: paramsToUse.px(expiration.getExpirationTime());
440443
}
441444

442-
return expiration.isUnixTimestamp() ? paramsToUse.exAt(expiration.getConverted(TimeUnit.SECONDS)) : paramsToUse.ex(expiration.getConverted(TimeUnit.SECONDS));
445+
return expiration.isUnixTimestamp() ? paramsToUse.exAt(expiration.getConverted(TimeUnit.SECONDS))
446+
: paramsToUse.ex(expiration.getConverted(TimeUnit.SECONDS));
443447
}
444448

445449
/**
@@ -814,6 +818,22 @@ public static byte[][] toBitfieldCommandArguments(BitFieldSubCommands source) {
814818
return args.toArray(new byte[0][0]);
815819
}
816820

821+
static FlushMode toFlushMode(@Nullable RedisServerCommands.FlushOption option) {
822+
823+
if (option == null) {
824+
return FlushMode.SYNC;
825+
}
826+
827+
switch (option) {
828+
case ASYNC:
829+
return FlushMode.ASYNC;
830+
case SYNC:
831+
return FlushMode.SYNC;
832+
default:
833+
throw new IllegalArgumentException("Flush option " + option + " is not supported.");
834+
}
835+
}
836+
817837
/**
818838
* @author Christoph Strobl
819839
* @since 1.8

src/main/java/org/springframework/data/redis/connection/jedis/JedisServerCommands.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import redis.clients.jedis.BinaryJedis;
1919
import redis.clients.jedis.Jedis;
2020
import redis.clients.jedis.MultiKeyPipelineBase;
21-
import redis.clients.jedis.args.FlushMode;
2221
import redis.clients.jedis.args.SaveMode;
2322

2423
import java.util.List;
@@ -39,8 +38,6 @@
3938
*/
4039
class JedisServerCommands implements RedisServerCommands {
4140

42-
private static final String SHUTDOWN_SCRIPT = "return redis.call('SHUTDOWN','%s')";
43-
4441
private final JedisConnection connection;
4542

4643
JedisServerCommands(JedisConnection connection) {
@@ -79,9 +76,8 @@ public void flushDb() {
7976

8077
@Override
8178
public void flushDb(FlushOption option) {
82-
83-
FlushMode flushMode = JedisClusterServerCommands.toFlushMode(option);
84-
connection.invokeStatus().just(it -> it.flushDB(flushMode), it -> it.flushDB(flushMode));
79+
connection.invokeStatus().just(BinaryJedis::flushDB, MultiKeyPipelineBase::flushDB,
80+
JedisConverters.toFlushMode(option));
8581
}
8682

8783
@Override
@@ -91,9 +87,8 @@ public void flushAll() {
9187

9288
@Override
9389
public void flushAll(FlushOption option) {
94-
95-
FlushMode flushMode = JedisClusterServerCommands.toFlushMode(option);
96-
connection.invokeStatus().just(it -> it.flushAll(flushMode), it -> it.flushAll(flushMode));
90+
connection.invokeStatus().just(BinaryJedis::flushAll, MultiKeyPipelineBase::flushAll,
91+
JedisConverters.toFlushMode(option));
9792
}
9893

9994
@Override

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterServerCommands.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void flushDb() {
9999

100100
@Override
101101
public void flushDb(FlushOption option) {
102-
executeCommandOnAllNodes(it -> it.flushdb(toFlushMode(option)));
102+
executeCommandOnAllNodes(it -> it.flushdb(LettuceConverters.toFlushMode(option)));
103103
}
104104

105105
@Override
@@ -109,7 +109,7 @@ public void flushDb(RedisClusterNode node) {
109109

110110
@Override
111111
public void flushDb(RedisClusterNode node, FlushOption option) {
112-
executeCommandOnSingleNode(it -> it.flushdb(toFlushMode(option)), node);
112+
executeCommandOnSingleNode(it -> it.flushdb(LettuceConverters.toFlushMode(option)), node);
113113
}
114114

115115
@Override
@@ -119,7 +119,7 @@ public void flushAll() {
119119

120120
@Override
121121
public void flushAll(FlushOption option) {
122-
executeCommandOnAllNodes(it -> it.flushall(toFlushMode(option)));
122+
executeCommandOnAllNodes(it -> it.flushall(LettuceConverters.toFlushMode(option)));
123123
}
124124

125125
@Override
@@ -129,7 +129,7 @@ public void flushAll(RedisClusterNode node) {
129129

130130
@Override
131131
public void flushAll(RedisClusterNode node, FlushOption option) {
132-
executeCommandOnSingleNode(it -> it.flushall(toFlushMode(option)), node);
132+
executeCommandOnSingleNode(it -> it.flushall(LettuceConverters.toFlushMode(option)), node);
133133
}
134134

135135
@Override

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConverters.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,10 +896,9 @@ public static GeoArgs toGeoArgs(GeoCommandArgs args) {
896896

897897
if (args.hasFlags()) {
898898
for (GeoCommandArgs.GeoCommandFlag flag : args.getFlags()) {
899-
if(flag.equals(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
899+
if (flag.equals(GeoRadiusCommandArgs.Flag.WITHCOORD)) {
900900
geoArgs.withCoordinates();
901-
}
902-
else if(flag.equals(GeoRadiusCommandArgs.Flag.WITHDIST)) {
901+
} else if (flag.equals(GeoRadiusCommandArgs.Flag.WITHDIST)) {
903902
geoArgs.withDistance();
904903
}
905904
}
@@ -1171,6 +1170,22 @@ static <T> GeoSearch.GeoRef<T> toGeoRef(GeoReference<T> reference) {
11711170
throw new IllegalArgumentException(String.format("Cannot convert %s to Lettuce GeoRef", reference));
11721171
}
11731172

1173+
static FlushMode toFlushMode(@Nullable RedisServerCommands.FlushOption option) {
1174+
1175+
if (option == null) {
1176+
return FlushMode.SYNC;
1177+
}
1178+
1179+
switch (option) {
1180+
case ASYNC:
1181+
return FlushMode.ASYNC;
1182+
case SYNC:
1183+
return FlushMode.SYNC;
1184+
default:
1185+
throw new IllegalArgumentException("Flush option " + option + " is not supported.");
1186+
}
1187+
}
1188+
11741189
/**
11751190
* @author Christoph Strobl
11761191
* @since 1.8

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Mono<String> flushDb(RedisClusterNode node) {
109109

110110
@Override
111111
public Mono<String> flushDb(RedisClusterNode node, FlushOption option) {
112-
return connection.execute(node, it -> it.flushdb(LettuceServerCommands.toFlushMode(option))).next();
112+
return connection.execute(node, it -> it.flushdb(LettuceConverters.toFlushMode(option))).next();
113113
}
114114

115115
@Override
@@ -119,7 +119,7 @@ public Mono<String> flushAll(RedisClusterNode node) {
119119

120120
@Override
121121
public Mono<String> flushAll(RedisClusterNode node, FlushOption option) {
122-
return connection.execute(node, it -> it.flushall(LettuceServerCommands.toFlushMode(option))).next();
122+
return connection.execute(node, it -> it.flushall(LettuceConverters.toFlushMode(option))).next();
123123
}
124124

125125
@Override

0 commit comments

Comments
 (0)