Skip to content

Commit 29a7ed7

Browse files
Add CONFIG REWRITE and CONFIG RESETSTAT. (#95)
* Add `CONFIG REWRITE` and `CONFIG RESETSTAT`. Signed-off-by: Yury-Fridlyand <[email protected]>
1 parent 0ee5ab0 commit 29a7ed7

14 files changed

+346
-7
lines changed

java/client/src/main/java/glide/api/BaseClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import static glide.ffi.resolvers.SocketListenerResolver.getSocket;
55
import static glide.utils.ArrayTransformUtils.castArray;
66
import static glide.utils.ArrayTransformUtils.convertMapToArgArray;
7+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
8+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
79
import static redis_request.RedisRequestOuterClass.RequestType.Decr;
810
import static redis_request.RedisRequestOuterClass.RequestType.DecrBy;
911
import static redis_request.RedisRequestOuterClass.RequestType.Del;
@@ -44,6 +46,7 @@
4446
import glide.api.commands.GenericBaseCommands;
4547
import glide.api.commands.HashCommands;
4648
import glide.api.commands.ListBaseCommands;
49+
import glide.api.commands.ServerManagementBaseCommands;
4750
import glide.api.commands.SetCommands;
4851
import glide.api.commands.StringCommands;
4952
import glide.api.models.commands.ExpireOptions;

java/client/src/main/java/glide/api/RedisClusterClient.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
22
package glide.api;
33

4+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
5+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
46
import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
57
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
68
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand;
@@ -181,4 +183,26 @@ public CompletableFuture<ClusterValue<String>> clientGetName(@NonNull Route rout
181183
? ClusterValue.of(handleStringOrNullResponse(response))
182184
: ClusterValue.of(handleMapResponse(response)));
183185
}
186+
187+
@Override
188+
public CompletableFuture<String> configRewrite() {
189+
return super.configRewrite();
190+
}
191+
192+
@Override
193+
public CompletableFuture<String> configRewrite(@NonNull Route route) {
194+
return commandManager.submitNewCommand(
195+
ConfigRewrite, new String[0], route, this::handleStringResponse);
196+
}
197+
198+
@Override
199+
public CompletableFuture<String> configResetStat() {
200+
return super.configResetStat();
201+
}
202+
203+
@Override
204+
public CompletableFuture<String> configResetStat(@NonNull Route route) {
205+
return commandManager.submitNewCommand(
206+
ConfigResetStat, new String[0], route, this::handleStringResponse);
207+
}
184208
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
2+
package glide.api.commands;
3+
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Server Management Commands interface for both standalone and cluster clients.
8+
*
9+
* @see <a href="https://redis.io/commands/?group=server">Server Management Commands</a>
10+
*/
11+
public interface ServerManagementBaseCommands {
12+
13+
/**
14+
* Rewrites the configuration file with the current configuration.
15+
*
16+
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
17+
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
18+
* raised.
19+
* @example
20+
* <pre>
21+
* String response = client.configRewrite().get();
22+
* assert response.equals("OK")
23+
* </pre>
24+
*/
25+
CompletableFuture<String> configRewrite();
26+
27+
/**
28+
* Resets the statistics reported by Redis using the <a
29+
* href="https://redis.io/commands/info/">INFO</a> and <a
30+
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM</a> commands.
31+
*
32+
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
33+
* @return <code>OK</code> to confirm that the statistics were successfully reset.
34+
* @example
35+
* <pre>
36+
* String response = client.configResetStat().get();
37+
* assert response.equals("OK")
38+
* </pre>
39+
*/
40+
CompletableFuture<String> configResetStat();
41+
}

java/client/src/main/java/glide/api/commands/ServerManagementClusterCommands.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.concurrent.CompletableFuture;
99

1010
/**
11-
* Server Management Commands interface.
11+
* Server Management Commands interface for cluster client.
1212
*
1313
* @see <a href="https://redis.io/commands/?group=server">Server Management Commands</a>
1414
*/
@@ -71,4 +71,68 @@ public interface ServerManagementClusterCommands {
7171
* value is the information of the sections requested for the node.
7272
*/
7373
CompletableFuture<ClusterValue<String>> info(InfoOptions options, Route route);
74+
75+
/**
76+
* Rewrites the configuration file with the current configuration.<br>
77+
* The command will be routed automatically to all nodes.
78+
*
79+
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
80+
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
81+
* raised.
82+
* @example
83+
* <pre>
84+
* String response = client.configRewrite().get();
85+
* assert response.equals("OK")
86+
* </pre>
87+
*/
88+
CompletableFuture<String> configRewrite();
89+
90+
/**
91+
* Rewrites the configuration file with the current configuration.
92+
*
93+
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
94+
* @param route Routing configuration for the command. Client will route the command to the nodes
95+
* defined.
96+
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
97+
* raised.
98+
* @example
99+
* <pre>
100+
* String response = client.configRewrite(ALL_PRIMARIES).get();
101+
* assert response.equals("OK")
102+
* </pre>
103+
*/
104+
CompletableFuture<String> configRewrite(Route route);
105+
106+
/**
107+
* Resets the statistics reported by Redis using the <a
108+
* href="https://redis.io/commands/info/">INFO</a> and <a
109+
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM </a> commands.<br>
110+
* The command will be routed automatically to all nodes.
111+
*
112+
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
113+
* @return <code>OK</code> to confirm that the statistics were successfully reset.
114+
* @example
115+
* <pre>
116+
* String response = client.configResetStat().get();
117+
* assert response.equals("OK")
118+
* </pre>
119+
*/
120+
CompletableFuture<String> configResetStat();
121+
122+
/**
123+
* Resets the statistics reported by Redis using the <a
124+
* href="https://redis.io/commands/info/">INFO</a> and <a
125+
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM </a> commands.
126+
*
127+
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
128+
* @param route Routing configuration for the command. Client will route the command to the nodes
129+
* defined.
130+
* @return <code>OK</code> to confirm that the statistics were successfully reset.
131+
* @example
132+
* <pre>
133+
* String response = client.configResetStat(ALL_PRIMARIES).get();
134+
* assert response.equals("OK")
135+
* </pre>
136+
*/
137+
CompletableFuture<String> configResetStat(Route route);
74138
}

java/client/src/main/java/glide/api/commands/ServerManagementCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.concurrent.CompletableFuture;
77

88
/**
9-
* Server Management Commands interface.
9+
* Server Management Commands interface for standalone client.
1010
*
1111
* @see <a href="https://redis.io/commands/?group=server">Server Management Commands</a>
1212
*/

java/client/src/main/java/glide/api/models/BaseTransaction.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package glide.api.models;
33

44
import static glide.utils.ArrayTransformUtils.convertMapToArgArray;
5+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
6+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
57
import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
68
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
79
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand;
@@ -991,6 +993,31 @@ public T clientGetName() {
991993
return getThis();
992994
}
993995

996+
/**
997+
* Rewrite the configuration file with the current configuration.
998+
*
999+
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
1000+
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
1001+
* raised.
1002+
*/
1003+
public T configRewrite() {
1004+
protobufTransaction.addCommands(buildCommand(ConfigRewrite));
1005+
return getThis();
1006+
}
1007+
1008+
/**
1009+
* Reset the statistics reported by Redis using the <a
1010+
* href="https://redis.io/commands/info/">INFO</a> and <a
1011+
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM </a> commands.
1012+
*
1013+
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
1014+
* @return <code>OK</code> to confirm that the statistics were successfully reset.
1015+
*/
1016+
public T configResetStat() {
1017+
protobufTransaction.addCommands(buildCommand(ConfigResetStat));
1018+
return getThis();
1019+
}
1020+
9941021
/** Build protobuf {@link Command} object for given command and arguments. */
9951022
protected Command buildCommand(RequestType requestType) {
9961023
return buildCommand(requestType, buildArgs());

java/client/src/test/java/glide/api/RedisClientTest.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import static org.mockito.ArgumentMatchers.eq;
1313
import static org.mockito.Mockito.mock;
1414
import static org.mockito.Mockito.when;
15+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
16+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
1517
import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
1618
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
1719
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand;
@@ -644,11 +646,6 @@ public void mset_returns_success() {
644646

645647
// exercise
646648
CompletableFuture<String> response = service.mset(keyValueMap);
647-
String payload = response.get();
648-
649-
// verify
650-
assertEquals(testResponse, response);
651-
assertEquals(OK, payload);
652649
}
653650

654651
@SneakyThrows
@@ -1326,4 +1323,40 @@ public void clientGetName_returns_success() {
13261323
assertEquals(testResponse, response);
13271324
assertEquals("TEST", response.get());
13281325
}
1326+
1327+
@SneakyThrows
1328+
@Test
1329+
public void configRewrite_returns_success() {
1330+
// setup
1331+
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
1332+
when(testResponse.get()).thenReturn(OK);
1333+
when(commandManager.<String>submitNewCommand(eq(ConfigRewrite), eq(new String[0]), any()))
1334+
.thenReturn(testResponse);
1335+
1336+
// exercise
1337+
CompletableFuture<String> response = service.configRewrite();
1338+
String payload = response.get();
1339+
1340+
// verify
1341+
assertEquals(testResponse, response);
1342+
assertEquals(OK, payload);
1343+
}
1344+
1345+
@SneakyThrows
1346+
@Test
1347+
public void configResetStat_returns_success() {
1348+
// setup
1349+
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
1350+
when(testResponse.get()).thenReturn(OK);
1351+
when(commandManager.<String>submitNewCommand(eq(ConfigResetStat), eq(new String[0]), any()))
1352+
.thenReturn(testResponse);
1353+
1354+
// exercise
1355+
CompletableFuture<String> response = service.configResetStat();
1356+
String payload = response.get();
1357+
1358+
// verify
1359+
assertEquals(testResponse, response);
1360+
assertEquals(OK, payload);
1361+
}
13291362
}

java/client/src/test/java/glide/api/RedisClusterClientTest.java

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
22
package glide.api;
33

4+
import static glide.api.BaseClient.OK;
45
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleRoute.ALL_NODES;
56
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleRoute.ALL_PRIMARIES;
67
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleRoute.RANDOM;
@@ -11,6 +12,8 @@
1112
import static org.mockito.ArgumentMatchers.eq;
1213
import static org.mockito.Mockito.mock;
1314
import static org.mockito.Mockito.when;
15+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
16+
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
1417
import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
1518
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
1619
import static redis_request.RedisRequestOuterClass.RequestType.Info;
@@ -441,4 +444,90 @@ public void clientGetName_with_multi_node_route_returns_success() {
441444
var value = client.clientGetName(ALL_NODES).get();
442445
assertEquals(data, value.getMultiValue());
443446
}
447+
448+
@SneakyThrows
449+
@Test
450+
public void configRewrite_without_route_returns_success() {
451+
// setup
452+
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
453+
when(testResponse.get()).thenReturn(OK);
454+
455+
// match on protobuf request
456+
when(commandManager.<String>submitNewCommand(eq(ConfigRewrite), eq(new String[0]), any()))
457+
.thenReturn(testResponse);
458+
459+
// exercise
460+
CompletableFuture<String> response = service.configRewrite();
461+
String payload = response.get();
462+
463+
// verify
464+
assertEquals(testResponse, response);
465+
assertEquals(OK, payload);
466+
}
467+
468+
@SneakyThrows
469+
@Test
470+
public void configRewrite_with_route_returns_success() {
471+
// setup
472+
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
473+
when(testResponse.get()).thenReturn(OK);
474+
475+
Route route = ALL_NODES;
476+
477+
// match on protobuf request
478+
when(commandManager.<String>submitNewCommand(
479+
eq(ConfigRewrite), eq(new String[0]), eq(route), any()))
480+
.thenReturn(testResponse);
481+
482+
// exercise
483+
CompletableFuture<String> response = service.configRewrite(route);
484+
String payload = response.get();
485+
486+
// verify
487+
assertEquals(testResponse, response);
488+
assertEquals(OK, payload);
489+
}
490+
491+
@SneakyThrows
492+
@Test
493+
public void configResetStat_without_route_returns_success() {
494+
// setup
495+
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
496+
when(testResponse.get()).thenReturn(OK);
497+
498+
// match on protobuf request
499+
when(commandManager.<String>submitNewCommand(eq(ConfigResetStat), eq(new String[0]), any()))
500+
.thenReturn(testResponse);
501+
502+
// exercise
503+
CompletableFuture<String> response = service.configResetStat();
504+
String payload = response.get();
505+
506+
// verify
507+
assertEquals(testResponse, response);
508+
assertEquals(OK, payload);
509+
}
510+
511+
@SneakyThrows
512+
@Test
513+
public void configResetStat_with_route_returns_success() {
514+
// setup
515+
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
516+
when(testResponse.get()).thenReturn(OK);
517+
518+
Route route = ALL_NODES;
519+
520+
// match on protobuf request
521+
when(commandManager.<String>submitNewCommand(
522+
eq(ConfigResetStat), eq(new String[0]), eq(route), any()))
523+
.thenReturn(testResponse);
524+
525+
// exercise
526+
CompletableFuture<String> response = service.configResetStat(route);
527+
String payload = response.get();
528+
529+
// verify
530+
assertEquals(testResponse, response);
531+
assertEquals(OK, payload);
532+
}
444533
}

java/client/src/test/java/glide/api/models/ClusterTransactionTests.java

Whitespace-only changes.

0 commit comments

Comments
 (0)