Skip to content

Commit

Permalink
Add CONFIG REWRITE and CONFIG RESETSTAT. (#1013)
Browse files Browse the repository at this point in the history
* Add `CONFIG REWRITE` and `CONFIG RESETSTAT`. (#95)

---------

Signed-off-by: Yury-Fridlyand <[email protected]>
Co-authored-by: SanHalacogluImproving <[email protected]>
  • Loading branch information
Yury-Fridlyand and SanHalacogluImproving authored Mar 6, 2024
1 parent 5c46015 commit b0dace0
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 2 deletions.
14 changes: 14 additions & 0 deletions java/client/src/main/java/glide/api/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand;
import static redis_request.RedisRequestOuterClass.RequestType.Info;
import static redis_request.RedisRequestOuterClass.RequestType.Ping;
Expand Down Expand Up @@ -88,4 +90,16 @@ public CompletableFuture<String> clientGetName() {
return commandManager.submitNewCommand(
ClientGetName, new String[0], this::handleStringOrNullResponse);
}

@Override
public CompletableFuture<String> configRewrite() {
return commandManager.submitNewCommand(
ConfigRewrite, new String[0], this::handleStringResponse);
}

@Override
public CompletableFuture<String> configResetStat() {
return commandManager.submitNewCommand(
ConfigResetStat, new String[0], this::handleStringResponse);
}
}
26 changes: 26 additions & 0 deletions java/client/src/main/java/glide/api/RedisClusterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand;
import static redis_request.RedisRequestOuterClass.RequestType.Info;
import static redis_request.RedisRequestOuterClass.RequestType.Ping;
Expand Down Expand Up @@ -181,4 +183,28 @@ public CompletableFuture<ClusterValue<String>> clientGetName(@NonNull Route rout
? ClusterValue.of(handleStringOrNullResponse(response))
: ClusterValue.of(handleMapResponse(response)));
}

@Override
public CompletableFuture<String> configRewrite() {
return commandManager.submitNewCommand(
ConfigRewrite, new String[0], this::handleStringResponse);
}

@Override
public CompletableFuture<String> configRewrite(@NonNull Route route) {
return commandManager.submitNewCommand(
ConfigRewrite, new String[0], route, this::handleStringResponse);
}

@Override
public CompletableFuture<String> configResetStat() {
return commandManager.submitNewCommand(
ConfigResetStat, new String[0], this::handleStringResponse);
}

@Override
public CompletableFuture<String> configResetStat(@NonNull Route route) {
return commandManager.submitNewCommand(
ConfigResetStat, new String[0], route, this::handleStringResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.concurrent.CompletableFuture;

/**
* Server Management Commands interface.
* Server Management Commands interface for cluster client.
*
* @see <a href="https://redis.io/commands/?group=server">Server Management Commands</a>
*/
Expand Down Expand Up @@ -71,4 +71,68 @@ public interface ServerManagementClusterCommands {
* value is the information of the sections requested for the node.
*/
CompletableFuture<ClusterValue<String>> info(InfoOptions options, Route route);

/**
* Rewrites the configuration file with the current configuration.<br>
* The command will be routed automatically to all nodes.
*
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
* thrown.
* @example
* <pre>{@code
* String response = client.configRewrite().get();
* assert response.equals("OK")
* }</pre>
*/
CompletableFuture<String> configRewrite();

/**
* Rewrites the configuration file with the current configuration.
*
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
* @param route Routing configuration for the command. Client will route the command to the nodes
* defined.
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
* thrown.
* @example
* <pre>{@code
* String response = client.configRewrite(ALL_PRIMARIES).get();
* assert response.equals("OK")
* }</pre>
*/
CompletableFuture<String> configRewrite(Route route);

/**
* Resets the statistics reported by Redis using the <a
* href="https://redis.io/commands/info/">INFO</a> and <a
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM</a> commands.<br>
* The command will be routed automatically to all nodes.
*
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
* @return <code>OK</code> to confirm that the statistics were successfully reset.
* @example
* <pre>{@code
* String response = client.configResetStat().get();
* assert response.equals("OK")
* }</pre>
*/
CompletableFuture<String> configResetStat();

/**
* Resets the statistics reported by Redis using the <a
* href="https://redis.io/commands/info/">INFO</a> and <a
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM</a> commands.
*
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
* @param route Routing configuration for the command. Client will route the command to the nodes
* defined.
* @return <code>OK</code> to confirm that the statistics were successfully reset.
* @example
* <pre>{@code
* String response = client.configResetStat(ALL_PRIMARIES).get();
* assert response.equals("OK")
* }</pre>
*/
CompletableFuture<String> configResetStat(Route route);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.concurrent.CompletableFuture;

/**
* Server Management Commands interface.
* Server Management Commands interface for standalone client.
*
* @see <a href="https://redis.io/commands/?group=server">Server Management Commands</a>
*/
Expand Down Expand Up @@ -40,4 +40,33 @@ public interface ServerManagementCommands {
* @return A simple <code>OK</code> response.
*/
CompletableFuture<String> select(long index);

/**
* Rewrites the configuration file with the current configuration.
*
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
* @return <code>OK</code> when the configuration was rewritten properly, otherwise an error is
* thrown.
* @example
* <pre>{@code
* String response = client.configRewrite().get();
* assert response.equals("OK");
* }</pre>
*/
CompletableFuture<String> configRewrite();

/**
* Resets the statistics reported by Redis using the <a
* href="https://redis.io/commands/info/">INFO</a> and <a
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM</a> commands.
*
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
* @return <code>OK</code> to confirm that the statistics were successfully reset.
* @example
* <pre>{@code
* String response = client.configResetStat().get();
* assert response.equals("OK");
* }</pre>
*/
CompletableFuture<String> configResetStat();
}
27 changes: 27 additions & 0 deletions java/client/src/main/java/glide/api/models/BaseTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static glide.utils.ArrayTransformUtils.convertMapToArgArray;
import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand;
import static redis_request.RedisRequestOuterClass.RequestType.Decr;
import static redis_request.RedisRequestOuterClass.RequestType.DecrBy;
Expand Down Expand Up @@ -991,6 +993,31 @@ public T clientGetName() {
return getThis();
}

/**
* Rewrites the configuration file with the current configuration.
*
* @see <a href="https://redis.io/commands/config-rewrite/">redis.io</a> for details.
* @return <code>OK</code> is returned when the configuration was rewritten properly. Otherwise,
* the transaction fails with an error.
*/
public T configRewrite() {
protobufTransaction.addCommands(buildCommand(ConfigRewrite));
return getThis();
}

/**
* Resets the statistics reported by Redis using the <a
* href="https://redis.io/commands/info/">INFO</a> and <a
* href="https://redis.io/commands/latency-histogram/">LATENCY HISTOGRAM</a> commands.
*
* @see <a href="https://redis.io/commands/config-resetstat/">redis.io</a> for details.
* @return <code>OK</code> to confirm that the statistics were successfully reset.
*/
public T configResetStat() {
protobufTransaction.addCommands(buildCommand(ConfigResetStat));
return getThis();
}

/** Build protobuf {@link Command} object for given command and arguments. */
protected Command buildCommand(RequestType requestType) {
return buildCommand(requestType, buildArgs());
Expand Down
42 changes: 42 additions & 0 deletions java/client/src/test/java/glide/api/RedisClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import static org.mockito.Mockito.when;
import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand;
import static redis_request.RedisRequestOuterClass.RequestType.Decr;
import static redis_request.RedisRequestOuterClass.RequestType.DecrBy;
Expand Down Expand Up @@ -1326,4 +1328,44 @@ public void clientGetName_returns_success() {
assertEquals(testResponse, response);
assertEquals("TEST", response.get());
}

@SneakyThrows
@Test
public void configRewrite_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);

// match on protobuf request
when(commandManager.<String>submitNewCommand(eq(ConfigRewrite), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.configRewrite();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}

@SneakyThrows
@Test
public void configResetStat_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);

// match on protobuf request
when(commandManager.<String>submitNewCommand(eq(ConfigResetStat), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.configResetStat();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}
}
89 changes: 89 additions & 0 deletions java/client/src/test/java/glide/api/RedisClusterClientTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api;

import static glide.api.BaseClient.OK;
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleRoute.ALL_NODES;
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleRoute.ALL_PRIMARIES;
import static glide.api.models.configuration.RequestRoutingConfiguration.SimpleRoute.RANDOM;
Expand All @@ -13,6 +14,8 @@
import static org.mockito.Mockito.when;
import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
import static redis_request.RedisRequestOuterClass.RequestType.ClientId;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigResetStat;
import static redis_request.RedisRequestOuterClass.RequestType.ConfigRewrite;
import static redis_request.RedisRequestOuterClass.RequestType.Info;
import static redis_request.RedisRequestOuterClass.RequestType.Ping;

Expand Down Expand Up @@ -441,4 +444,90 @@ public void clientGetName_with_multi_node_route_returns_success() {
var value = client.clientGetName(ALL_NODES).get();
assertEquals(data, value.getMultiValue());
}

@SneakyThrows
@Test
public void configRewrite_without_route_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);

// match on protobuf request
when(commandManager.<String>submitNewCommand(eq(ConfigRewrite), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.configRewrite();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}

@SneakyThrows
@Test
public void configRewrite_with_route_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);

Route route = ALL_NODES;

// match on protobuf request
when(commandManager.<String>submitNewCommand(
eq(ConfigRewrite), eq(new String[0]), eq(route), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.configRewrite(route);
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}

@SneakyThrows
@Test
public void configResetStat_without_route_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);

// match on protobuf request
when(commandManager.<String>submitNewCommand(eq(ConfigResetStat), eq(new String[0]), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.configResetStat();
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}

@SneakyThrows
@Test
public void configResetStat_with_route_returns_success() {
// setup
CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(OK);

Route route = ALL_NODES;

// match on protobuf request
when(commandManager.<String>submitNewCommand(
eq(ConfigResetStat), eq(new String[0]), eq(route), any()))
.thenReturn(testResponse);

// exercise
CompletableFuture<String> response = service.configResetStat(route);
String payload = response.get();

// verify
assertEquals(testResponse, response);
assertEquals(OK, payload);
}
}
Loading

0 comments on commit b0dace0

Please sign in to comment.