Skip to content

Commit 3879a5a

Browse files
schnapstermp911de
authored andcommitted
Add support for flush modes using FLUSHDB and FLUSHALL commands.
Closes #2187 Original pull request: #2190.
1 parent a0b70a3 commit 3879a5a

22 files changed

+813
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
* @author Andrey Shlykov
7676
* @author dengliming
7777
* @author ihaohong
78+
* @author Dennis Neufeld
7879
*/
7980
public class DefaultStringRedisConnection implements StringRedisConnection, DecoratedRedisConnection {
8081

@@ -401,6 +402,15 @@ public void flushAll() {
401402
delegate.flushAll();
402403
}
403404

405+
/*
406+
* (non-Javadoc)
407+
* @see org.springframework.data.redis.connection.RedisServerCommands#flushAll(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
408+
*/
409+
@Override
410+
public void flushAll(FlushOption option) {
411+
delegate.flushAll(option);
412+
}
413+
404414
/*
405415
* (non-Javadoc)
406416
* @see org.springframework.data.redis.connection.RedisServerCommands#flushDb()
@@ -410,6 +420,15 @@ public void flushDb() {
410420
delegate.flushDb();
411421
}
412422

423+
/*
424+
* (non-Javadoc)
425+
* @see org.springframework.data.redis.connection.RedisServerCommands#flushDb(org.springframework.data.redis.connection.RedisServerCommands.FlushOption)
426+
*/
427+
@Override
428+
public void flushDb(FlushOption option) {
429+
delegate.flushDb(option);
430+
}
431+
413432
/*
414433
* (non-Javadoc)
415434
* @see org.springframework.data.redis.connection.RedisStringCommands#get(byte[])

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/**
2828
* @author Christoph Strobl
2929
* @author Mark Paluch
30+
* @author Dennis Neufeld
3031
* @since 2.0
3132
*/
3233
public interface DefaultedRedisClusterConnection extends RedisClusterConnection, DefaultedRedisConnection {
@@ -73,13 +74,27 @@ default void flushDb(RedisClusterNode node) {
7374
serverCommands().flushDb(node);
7475
}
7576

77+
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
78+
@Override
79+
@Deprecated
80+
default void flushDb(RedisClusterNode node, FlushOption option) {
81+
serverCommands().flushDb(node, option);
82+
}
83+
7684
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
7785
@Override
7886
@Deprecated
7987
default void flushAll(RedisClusterNode node) {
8088
serverCommands().flushAll(node);
8189
}
8290

91+
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
92+
@Override
93+
@Deprecated
94+
default void flushAll(RedisClusterNode node, FlushOption option) {
95+
serverCommands().flushAll(node, option);
96+
}
97+
8398
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
8499
@Override
85100
@Deprecated

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
* @author Andrey Shlykov
6161
* @author dengliming
6262
* @author ihaohong
63+
* @author Dennis Neufeld
6364
* @since 2.0
6465
*/
6566
public interface DefaultedRedisConnection extends RedisConnection {
@@ -1632,13 +1633,27 @@ default void flushDb() {
16321633
serverCommands().flushDb();
16331634
}
16341635

1636+
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
1637+
@Override
1638+
@Deprecated
1639+
default void flushDb(FlushOption option) {
1640+
serverCommands().flushDb(option);
1641+
}
1642+
16351643
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
16361644
@Override
16371645
@Deprecated
16381646
default void flushAll() {
16391647
serverCommands().flushAll();
16401648
}
16411649

1650+
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
1651+
@Override
1652+
@Deprecated
1653+
default void flushAll(FlushOption option) {
1654+
serverCommands().flushAll(option);
1655+
}
1656+
16421657
/** @deprecated in favor of {@link RedisConnection#serverCommands()}. */
16431658
@Override
16441659
@Deprecated

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
import java.util.Properties;
2222

23+
import org.springframework.data.redis.connection.RedisServerCommands.FlushOption;
2324
import org.springframework.data.redis.core.types.RedisClientInfo;
2425

2526
/**
2627
* Redis Server commands executed in cluster environment using reactive infrastructure.
2728
*
2829
* @author Mark Paluch
2930
* @author Christoph Strobl
31+
* @author Dennis Neufeld
3032
* @since 2.0
3133
*/
3234
public interface ReactiveClusterServerCommands extends ReactiveServerCommands {
@@ -91,6 +93,17 @@ public interface ReactiveClusterServerCommands extends ReactiveServerCommands {
9193
*/
9294
Mono<String> flushDb(RedisClusterNode node);
9395

96+
/**
97+
* Delete all keys of the currently selected database using the specified flush option.
98+
*
99+
* @param node must not be {@literal null}. {@link Mono} indicating command completion.
100+
* @param option
101+
* @throws IllegalArgumentException when {@code node} is {@literal null}.
102+
* @see RedisServerCommands#flushDb(FlushOption)
103+
* @since 2.6
104+
*/
105+
Mono<String> flushDb(RedisClusterNode node, FlushOption option);
106+
94107
/**
95108
* Delete all <b>all keys</b> from <b>all databases</b>.
96109
*
@@ -101,6 +114,18 @@ public interface ReactiveClusterServerCommands extends ReactiveServerCommands {
101114
*/
102115
Mono<String> flushAll(RedisClusterNode node);
103116

117+
/**
118+
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
119+
*
120+
* @param node must not be {@literal null}.
121+
* @param option
122+
* @return {@link Mono} indicating command completion.
123+
* @throws IllegalArgumentException when {@code node} is {@literal null}.
124+
* @see RedisServerCommands#flushAll(FlushOption)
125+
* @since 2.6
126+
*/
127+
Mono<String> flushAll(RedisClusterNode node, FlushOption option);
128+
104129
/**
105130
* Load {@literal default} server information like
106131
* <ul>

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
import java.util.Properties;
2222
import java.util.concurrent.TimeUnit;
2323

24+
import org.springframework.data.redis.connection.RedisServerCommands.FlushOption;
2425
import org.springframework.data.redis.core.types.RedisClientInfo;
2526

2627
/**
2728
* Redis Server commands executed using reactive infrastructure.
2829
*
2930
* @author Mark Paluch
3031
* @author Christoph Strobl
32+
* @author Dennis Neufeld
3133
* @since 2.0
3234
*/
3335
public interface ReactiveServerCommands {
@@ -81,6 +83,16 @@ public interface ReactiveServerCommands {
8183
*/
8284
Mono<String> flushDb();
8385

86+
/**
87+
* Delete all keys of the currently selected database using the specified flush option.
88+
*
89+
* @param option
90+
* @return {@link Mono} indicating command completion.
91+
* @see <a href="https://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
92+
* @since 2.6
93+
*/
94+
Mono<String> flushDb(FlushOption option);
95+
8496
/**
8597
* Delete all <b>all keys</b> from <b>all databases</b>.
8698
*
@@ -89,6 +101,16 @@ public interface ReactiveServerCommands {
89101
*/
90102
Mono<String> flushAll();
91103

104+
/**
105+
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
106+
*
107+
* @param option
108+
* @return {@link Mono} indicating command completion.
109+
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
110+
* @since 2.6
111+
*/
112+
Mono<String> flushAll(FlushOption option);
113+
92114
/**
93115
* Load {@literal default} server information like
94116
* <ul>

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

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

2424
/**
2525
* @author Mark Paluch
26+
* @author Dennis Neufeld
2627
* @since 2.0
2728
*/
2829
public interface RedisClusterServerCommands extends RedisServerCommands {
@@ -65,12 +66,28 @@ public interface RedisClusterServerCommands extends RedisServerCommands {
6566
*/
6667
void flushDb(RedisClusterNode node);
6768

69+
/**
70+
* @param node must not be {@literal null}.
71+
* @param option
72+
* @see RedisServerCommands#flushDb(FlushOption)
73+
* @since 2.6
74+
*/
75+
void flushDb(RedisClusterNode node, FlushOption option);
76+
6877
/**
6978
* @param node must not be {@literal null}.
7079
* @see RedisServerCommands#flushAll()
7180
*/
7281
void flushAll(RedisClusterNode node);
7382

83+
/**
84+
* @param node must not be {@literal null}.
85+
* @param option
86+
* @see RedisServerCommands#flushAll(FlushOption)
87+
* @since 2.6
88+
*/
89+
void flushAll(RedisClusterNode node, FlushOption option);
90+
7491
/**
7592
* @param node must not be {@literal null}.
7693
* @return

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @author Christoph Strobl
3030
* @author Thomas Darimont
3131
* @author Mark Paluch
32+
* @author Dennis Neufeld
3233
*/
3334
public interface RedisServerCommands {
3435

@@ -43,6 +44,13 @@ enum MigrateOption {
4344
COPY, REPLACE
4445
}
4546

47+
/**
48+
* @since 2.6
49+
*/
50+
enum FlushOption {
51+
SYNC, ASYNC
52+
}
53+
4654
/**
4755
* Start an {@literal Append Only File} rewrite process on server.
4856
*
@@ -101,13 +109,31 @@ default void bgWriteAof() {
101109
*/
102110
void flushDb();
103111

112+
/**
113+
* Delete all keys of the currently selected database using the specified flush option.
114+
*
115+
* @param option
116+
* @see <a href="https://redis.io/commands/flushdb">Redis Documentation: FLUSHDB</a>
117+
* @since 2.6
118+
*/
119+
void flushDb(FlushOption option);
120+
104121
/**
105122
* Delete all <b>all keys</b> from <b>all databases</b>.
106123
*
107124
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
108125
*/
109126
void flushAll();
110127

128+
/**
129+
* Delete all <b>all keys</b> from <b>all databases</b> using the specified flush option.
130+
*
131+
* @param option
132+
* @see <a href="https://redis.io/commands/flushall">Redis Documentation: FLUSHALL</a>
133+
* @since 2.6
134+
*/
135+
void flushAll(FlushOption option);
136+
111137
/**
112138
* Load {@literal default} server information like
113139
* <ul>

0 commit comments

Comments
 (0)