From c31877e23e64fbae9dde0e2c74f81b174d840704 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 20 Feb 2024 13:54:38 -0800 Subject: [PATCH 1/6] Add `CLIENT ID` and `CLIENT GETNAME` commands. Signed-off-by: Yury-Fridlyand --- .../src/main/java/glide/api/BaseClient.java | 19 ++++- .../src/main/java/glide/api/RedisClient.java | 13 +++ .../java/glide/api/RedisClusterClient.java | 41 ++++++++- ... => ConnectionManagementBaseCommands.java} | 23 ++++- .../ConnectionManagementClusterCommands.java | 32 ++++++- .../glide/api/models/BaseTransaction.java | 25 ++++++ .../glide/api/RedisClusterClientTest.java | 83 ++++++++++++++++++- .../glide/api/models/TransactionTests.java | 6 ++ .../test/java/glide/SharedCommandTests.java | 2 +- .../src/test/java/glide/TestUtilities.java | 14 ++++ .../test/java/glide/cluster/CommandTests.java | 73 ++++++++++++++++ 11 files changed, 319 insertions(+), 12 deletions(-) rename java/client/src/main/java/glide/api/commands/{ConnectionManagementCommands.java => ConnectionManagementBaseCommands.java} (50%) create mode 100644 java/integTest/src/test/java/glide/TestUtilities.java diff --git a/java/client/src/main/java/glide/api/BaseClient.java b/java/client/src/main/java/glide/api/BaseClient.java index 752fd3020a..1a5d42fa27 100644 --- a/java/client/src/main/java/glide/api/BaseClient.java +++ b/java/client/src/main/java/glide/api/BaseClient.java @@ -4,6 +4,8 @@ import static glide.ffi.resolvers.SocketListenerResolver.getSocket; import static glide.utils.ArrayTransformUtils.castArray; 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.Decr; import static redis_request.RedisRequestOuterClass.RequestType.DecrBy; import static redis_request.RedisRequestOuterClass.RequestType.GetString; @@ -22,7 +24,7 @@ import static redis_request.RedisRequestOuterClass.RequestType.SRem; import static redis_request.RedisRequestOuterClass.RequestType.SetString; -import glide.api.commands.ConnectionManagementCommands; +import glide.api.commands.ConnectionManagementBaseCommands; import glide.api.commands.HashCommands; import glide.api.commands.SetCommands; import glide.api.commands.StringCommands; @@ -53,10 +55,11 @@ @AllArgsConstructor public abstract class BaseClient implements AutoCloseable, - ConnectionManagementCommands, + ConnectionManagementBaseCommands, StringCommands, HashCommands, SetCommands { + /** Redis simple string response with "OK" */ public static final String OK = ConstantResponse.OK.toString(); @@ -188,7 +191,7 @@ protected Object[] handleArrayOrNullResponse(Response response) throws RedisExce /** * @param response A Protobuf response * @return A map of String to V - * @param Value type could be even map too + * @param Value type, could be even map too */ @SuppressWarnings("unchecked") // raw Map cast to Map protected Map handleMapResponse(Response response) throws RedisException { @@ -309,4 +312,14 @@ public CompletableFuture> smembers(String key) { public CompletableFuture scard(String key) { return commandManager.submitNewCommand(SCard, new String[] {key}, this::handleLongResponse); } + + public CompletableFuture clientId() { + return commandManager.submitNewCommand(ClientId, new String[0], this::handleLongResponse); + } + + @Override + public CompletableFuture clientGetName() { + return commandManager.submitNewCommand( + ClientGetName, new String[0], this::handleStringOrNullResponse); + } } diff --git a/java/client/src/main/java/glide/api/RedisClient.java b/java/client/src/main/java/glide/api/RedisClient.java index 94af58bd42..fc40b73661 100644 --- a/java/client/src/main/java/glide/api/RedisClient.java +++ b/java/client/src/main/java/glide/api/RedisClient.java @@ -1,6 +1,8 @@ /** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api; +import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName; +import static redis_request.RedisRequestOuterClass.RequestType.ClientId; import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand; import static redis_request.RedisRequestOuterClass.RequestType.Info; @@ -54,4 +56,15 @@ public CompletableFuture info() { public CompletableFuture info(@NonNull InfoOptions options) { return commandManager.submitNewCommand(Info, options.toArgs(), this::handleStringResponse); } + + @Override + public CompletableFuture clientId() { + return commandManager.submitNewCommand(ClientId, new String[0], this::handleLongResponse); + } + + @Override + public CompletableFuture clientGetName() { + return commandManager.submitNewCommand( + ClientGetName, new String[0], this::handleStringOrNullResponse); + } } diff --git a/java/client/src/main/java/glide/api/RedisClusterClient.java b/java/client/src/main/java/glide/api/RedisClusterClient.java index cfdf1bd072..90999ccf42 100644 --- a/java/client/src/main/java/glide/api/RedisClusterClient.java +++ b/java/client/src/main/java/glide/api/RedisClusterClient.java @@ -1,6 +1,8 @@ /** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api; +import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName; +import static redis_request.RedisRequestOuterClass.RequestType.ClientId; import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand; import static redis_request.RedisRequestOuterClass.RequestType.Info; import static redis_request.RedisRequestOuterClass.RequestType.Ping; @@ -53,7 +55,8 @@ public CompletableFuture> customCommand(@NonNull String[] a } @Override - public CompletableFuture> customCommand(String[] args, Route route) { + public CompletableFuture> customCommand( + @NonNull String[] args, @NonNull Route route) { return commandManager.submitNewCommand( CustomCommand, args, route, response -> handleCustomCommandResponse(route, response)); } @@ -132,4 +135,40 @@ public CompletableFuture> info( ? ClusterValue.of(handleStringResponse(response)) : ClusterValue.of(handleMapResponse(response))); } + + /** {@inheritDoc} The command will be routed a random node. */ + @Override + public CompletableFuture clientId() { + return super.clientId(); + } + + /** {@inheritDoc} The command will be routed a random node. */ + @Override + public CompletableFuture clientGetName() { + return super.clientGetName(); + } + + @Override + public CompletableFuture> clientId(@NonNull Route route) { + return commandManager.submitNewCommand( + ClientId, + new String[0], + route, + response -> + route.isSingleNodeRoute() + ? ClusterValue.of(handleLongResponse(response)) + : ClusterValue.of(handleMapResponse(response))); + } + + @Override + public CompletableFuture> clientGetName(@NonNull Route route) { + return commandManager.submitNewCommand( + ClientGetName, + new String[0], + route, + response -> + route.isSingleNodeRoute() + ? ClusterValue.of(handleStringOrNullResponse(response)) + : ClusterValue.of(handleMapResponse(response))); + } } diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java similarity index 50% rename from java/client/src/main/java/glide/api/commands/ConnectionManagementCommands.java rename to java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java index 5f4027bdd1..ebe871d0c2 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java @@ -4,11 +4,11 @@ import java.util.concurrent.CompletableFuture; /** - * Connection Management Commands interface. + * Connection Management Commands interface for both standalone and cluster clients. * - * @see: Connection Management Commands + * @see Connection Management Commands */ -public interface ConnectionManagementCommands { +public interface ConnectionManagementBaseCommands { /** * Ping the Redis server. @@ -27,4 +27,21 @@ public interface ConnectionManagementCommands { * str. */ CompletableFuture ping(String str); + + /** + * Get the current connection id. + * + * @see redis.io for details. + * @return The id of the client. + */ + CompletableFuture clientId(); + + /** + * Get the name of the current connection. + * + * @see redis.io for details. + * @return The name of the client connection as a string if a name is set, or null if no name is + * assigned. + */ + CompletableFuture clientGetName(); } diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java index a3d5f03e6b..d8e05fa43f 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java @@ -1,13 +1,14 @@ /** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ package glide.api.commands; +import glide.api.models.ClusterValue; import glide.api.models.configuration.RequestRoutingConfiguration.Route; import java.util.concurrent.CompletableFuture; /** - * Connection Management Commands interface. + * Connection Management Commands interface for cluster client. * - * @see: Connection Management Commands + * @see Connection Management Commands */ public interface ConnectionManagementClusterCommands { @@ -17,7 +18,7 @@ public interface ConnectionManagementClusterCommands { * @see redis.io for details. * @param route Routing configuration for the command. Client will route the command to the nodes * defined. - * @return Response from Redis containing a String with "PONG". + * @return Response from Redis containing a String with PONG. */ CompletableFuture ping(Route route); @@ -32,4 +33,29 @@ public interface ConnectionManagementClusterCommands { * str. */ CompletableFuture ping(String str, Route route); + + /** + * Get the current connection id. + * + * @see redis.io for details. + * @param route Routing configuration for the command. Client will route the command to the nodes + * defined. + * @return A {@link ClusterValue} which holds a single value if single node route is used or a + * dictionary where each address is the key and its corresponding node response is the value. + * The value is the id of the client on that node. + */ + CompletableFuture> clientId(Route route); + + /** + * Get the name of the current connection. + * + * @see redis.io for details. + * @param route Routing configuration for the command. Client will route the command to the nodes + * defined. + * @return A {@link ClusterValue} which holds a single value if single node route is used or a + * dictionary where each address is the key and its corresponding node response is the value. + * The value is the name of the client connection as a string if a name is set, or null if no + * name is assigned. + */ + CompletableFuture> clientGetName(Route route); } diff --git a/java/client/src/main/java/glide/api/models/BaseTransaction.java b/java/client/src/main/java/glide/api/models/BaseTransaction.java index ad087ed457..88730a6138 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -2,6 +2,8 @@ package glide.api.models; 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.CustomCommand; import static redis_request.RedisRequestOuterClass.RequestType.Decr; import static redis_request.RedisRequestOuterClass.RequestType.DecrBy; @@ -413,6 +415,29 @@ public T scard(String key) { return getThis(); } + /** + * Get the current connection id. + * + * @see redis.io for details. + * @return Command response - The id of the client. + */ + public T clientId() { + protobufTransaction.addCommands(buildCommand(ClientId)); + return getThis(); + } + + /** + * Get the name of the current connection. + * + * @see redis.io for details. + * @return Command response - The name of the client connection as a string if a name is set, or + * null if no name is assigned. + */ + public T clientGetName() { + protobufTransaction.addCommands(buildCommand(ClientGetName)); + return getThis(); + } + /** Build protobuf {@link Command} object for given command and arguments. */ protected Command buildCommand(RequestType requestType) { return buildCommand(requestType, buildArgs()); diff --git a/java/client/src/test/java/glide/api/RedisClusterClientTest.java b/java/client/src/test/java/glide/api/RedisClusterClientTest.java index d79150daed..fe525b3e59 100644 --- a/java/client/src/test/java/glide/api/RedisClusterClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClusterClientTest.java @@ -11,6 +11,8 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; 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.Info; import static redis_request.RedisRequestOuterClass.RequestType.Ping; @@ -118,7 +120,6 @@ public TestClient(CommandManager commandManager, Object objectToReturn) { object = objectToReturn; } - @SuppressWarnings("unchecked") @Override protected T handleRedisResponse(Class classType, boolean isNullable, Response response) { return (T) object; @@ -314,4 +315,84 @@ public void info_with_options_and_multi_node_route_returns_multi_value() { assertAll( () -> assertTrue(value.hasMultiData()), () -> assertEquals(data, value.getMultiValue())); } + + @SneakyThrows + @Test + public void clientId_returns_success() { + // setup + CompletableFuture testResponse = mock(CompletableFuture.class); + when(testResponse.get()).thenReturn(42L); + when(commandManager.submitNewCommand(eq(ClientId), eq(new String[0]), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.clientId(); + + // verify + assertEquals(testResponse, response); + assertEquals(42L, response.get()); + } + + @Test + @SneakyThrows + public void clientId_with_multi_node_route_returns_success() { + var commandManager = new TestCommandManager(null); + + var data = Map.of("n1", 42L); + var client = new TestClient(commandManager, data); + + var value = client.clientId(ALL_NODES).get(); + assertEquals(data, value.getMultiValue()); + } + + @Test + @SneakyThrows + public void clientId_with_single_node_route_returns_success() { + var commandManager = new TestCommandManager(null); + + var client = new TestClient(commandManager, 42L); + + var value = client.clientId(RANDOM).get(); + assertEquals(42, value.getSingleValue()); + } + + @SneakyThrows + @Test + public void clientGetName_returns_success() { + // setup + CompletableFuture testResponse = mock(CompletableFuture.class); + when(testResponse.get()).thenReturn("TEST"); + when(commandManager.submitNewCommand(eq(ClientGetName), eq(new String[0]), any())) + .thenReturn(testResponse); + + // exercise + CompletableFuture response = service.clientGetName(); + + // verify + assertEquals(testResponse, response); + assertEquals("TEST", response.get()); + } + + @Test + @SneakyThrows + public void clientGetName_with_single_node_route_returns_success() { + var commandManager = new TestCommandManager(null); + + var client = new TestClient(commandManager, "TEST"); + + var value = client.clientGetName(RANDOM).get(); + assertEquals("TEST", value.getSingleValue()); + } + + @Test + @SneakyThrows + public void clientGetName_with_multi_node_route_returns_success() { + var commandManager = new TestCommandManager(null); + + var data = Map.of("n1", "TEST"); + var client = new TestClient(commandManager, data); + + var value = client.clientGetName(ALL_NODES).get(); + assertEquals(data, value.getMultiValue()); + } } diff --git a/java/client/src/test/java/glide/api/models/TransactionTests.java b/java/client/src/test/java/glide/api/models/TransactionTests.java index 1c74305613..98d9e3077c 100644 --- a/java/client/src/test/java/glide/api/models/TransactionTests.java +++ b/java/client/src/test/java/glide/api/models/TransactionTests.java @@ -3,6 +3,8 @@ import static glide.api.models.commands.SetOptions.RETURN_OLD_VALUE; import static org.junit.jupiter.api.Assertions.assertEquals; +import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName; +import static redis_request.RedisRequestOuterClass.RequestType.ClientId; import static redis_request.RedisRequestOuterClass.RequestType.Decr; import static redis_request.RedisRequestOuterClass.RequestType.DecrBy; import static redis_request.RedisRequestOuterClass.RequestType.GetString; @@ -116,6 +118,10 @@ public void transaction_builds_protobuf_request() { transaction.scard("key"); results.add(Pair.of(SCard, ArgsArray.newBuilder().addArgs("key").build())); + transaction.clientId().clientGetName(); + results.add(Pair.of(ClientId, ArgsArray.newBuilder().build())); + results.add(Pair.of(ClientGetName, ArgsArray.newBuilder().build())); + var protobufTransaction = transaction.getProtobufTransaction().build(); for (int idx = 0; idx < protobufTransaction.getCommandsCount(); idx++) { diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index 534e2e73fd..e191fabf0b 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -252,7 +252,7 @@ public void set_missing_value_and_returnOldValue_is_null(BaseClient client) { assertEquals(OK, ok); SetOptions options = SetOptions.builder().returnOldValue(true).build(); - String data = client.set("another", ANOTHER_VALUE, options).get(); + String data = client.set(UUID.randomUUID().toString(), ANOTHER_VALUE, options).get(); assertNull(data); } diff --git a/java/integTest/src/test/java/glide/TestUtilities.java b/java/integTest/src/test/java/glide/TestUtilities.java new file mode 100644 index 0000000000..49570a117e --- /dev/null +++ b/java/integTest/src/test/java/glide/TestUtilities.java @@ -0,0 +1,14 @@ +/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ +package glide; + +import glide.api.models.ClusterValue; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class TestUtilities { + + /** Extract first value from {@link ClusterValue} assuming it contains a multi-value. */ + public static T getFirstEntryFromMultiValue(ClusterValue data) { + return data.getMultiValue().get(data.getMultiValue().keySet().toArray(String[]::new)[0]); + } +} diff --git a/java/integTest/src/test/java/glide/cluster/CommandTests.java b/java/integTest/src/test/java/glide/cluster/CommandTests.java index 38973aa581..4c82bc74c5 100644 --- a/java/integTest/src/test/java/glide/cluster/CommandTests.java +++ b/java/integTest/src/test/java/glide/cluster/CommandTests.java @@ -3,6 +3,7 @@ import static glide.TestConfiguration.CLUSTER_PORTS; import static glide.TestConfiguration.REDIS_VERSION; +import static glide.TestUtilities.getFirstEntryFromMultiValue; import static glide.api.models.commands.InfoOptions.Section.CLIENTS; import static glide.api.models.commands.InfoOptions.Section.CLUSTER; import static glide.api.models.commands.InfoOptions.Section.COMMANDSTATS; @@ -260,4 +261,76 @@ public void info_with_multi_node_route_and_options() { } } } + + @Test + @SneakyThrows + public void clientId() { + var currentId = clusterClient.clientId().get(); + + try (var newClient = + RedisClusterClient.CreateClient( + RedisClusterClientConfiguration.builder() + .address(NodeAddress.builder().port(CLUSTER_PORTS[0]).build()) + .requestTimeout(5000) + .build()) + .get()) { + + var newClientId = newClient.clientId().get(); + + assertTrue(currentId < newClientId); + } + } + + @Test + @SneakyThrows + public void clientId_with_single_node_route() { + var data = clusterClient.clientId(RANDOM).get(); + assertTrue(data.getSingleValue() > 0L); + } + + @Test + @SneakyThrows + public void clientId_with_multi_node_route() { + var data = clusterClient.clientId(ALL_NODES).get(); + data.getMultiValue().values().forEach(id -> assertTrue(id > 0)); + } + + @Test + @SneakyThrows + public void clientGetName() { + // TODO replace with the corresponding command once implemented + clusterClient.customCommand(new String[] {"client", "setname", "clientGetName"}).get(); + + var name = clusterClient.clientGetName().get(); + + assertEquals("clientGetName", name); + } + + @Test + @SneakyThrows + public void clientGetName_with_single_node_route() { + // TODO replace with the corresponding command once implemented + clusterClient + .customCommand( + new String[] {"client", "setname", "clientGetName_with_single_node_route"}, ALL_NODES) + .get(); + + var name = clusterClient.clientGetName(RANDOM).get(); + + assertEquals("clientGetName_with_single_node_route", name.getSingleValue()); + } + + @Test + @SneakyThrows + public void clientGetName_with_multi_node_route() { + // TODO replace with the corresponding command once implemented + clusterClient + .customCommand( + new String[] {"client", "setname", "clientGetName_with_multi_node_route"}, ALL_NODES) + .get(); + + var name = clusterClient.clientGetName(ALL_NODES).get(); + + assertEquals("clientGetName_with_multi_node_route", getFirstEntryFromMultiValue(name)); + } } From 817edf6c0a97bab1fda04201033471f21337617a Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 20 Feb 2024 14:11:49 -0800 Subject: [PATCH 2/6] javajavadocdoc Signed-off-by: Yury-Fridlyand --- .../glide/api/commands/ConnectionManagementBaseCommands.java | 4 ++-- .../src/main/java/glide/api/models/BaseTransaction.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java index ebe871d0c2..36b6fe6957 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java @@ -40,8 +40,8 @@ public interface ConnectionManagementBaseCommands { * Get the name of the current connection. * * @see redis.io for details. - * @return The name of the client connection as a string if a name is set, or null if no name is - * assigned. + * @return The name of the client connection as a string if a name is set, or null if + * no name is assigned. */ CompletableFuture clientGetName(); } diff --git a/java/client/src/main/java/glide/api/models/BaseTransaction.java b/java/client/src/main/java/glide/api/models/BaseTransaction.java index 88730a6138..5b32db1d6f 100644 --- a/java/client/src/main/java/glide/api/models/BaseTransaction.java +++ b/java/client/src/main/java/glide/api/models/BaseTransaction.java @@ -431,7 +431,7 @@ public T clientId() { * * @see redis.io for details. * @return Command response - The name of the client connection as a string if a name is set, or - * null if no name is assigned. + * null if no name is assigned. */ public T clientGetName() { protobufTransaction.addCommands(buildCommand(ClientGetName)); From cf519a0cba719aa738a1b68a5912988a98ce5ca5 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 20 Feb 2024 14:16:44 -0800 Subject: [PATCH 3/6] Add interface inheritance to inherit & extend javadocs. Signed-off-by: Yury-Fridlyand --- .../src/main/java/glide/api/RedisClusterClient.java | 2 -- .../api/commands/ConnectionManagementClusterCommands.java | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/java/client/src/main/java/glide/api/RedisClusterClient.java b/java/client/src/main/java/glide/api/RedisClusterClient.java index 90999ccf42..028c3a566a 100644 --- a/java/client/src/main/java/glide/api/RedisClusterClient.java +++ b/java/client/src/main/java/glide/api/RedisClusterClient.java @@ -136,13 +136,11 @@ public CompletableFuture> info( : ClusterValue.of(handleMapResponse(response))); } - /** {@inheritDoc} The command will be routed a random node. */ @Override public CompletableFuture clientId() { return super.clientId(); } - /** {@inheritDoc} The command will be routed a random node. */ @Override public CompletableFuture clientGetName() { return super.clientGetName(); diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java index d8e05fa43f..b5e1f0d9ee 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java @@ -10,7 +10,7 @@ * * @see Connection Management Commands */ -public interface ConnectionManagementClusterCommands { +public interface ConnectionManagementClusterCommands extends ConnectionManagementBaseCommands { /** * Ping the Redis server. @@ -34,6 +34,12 @@ public interface ConnectionManagementClusterCommands { */ CompletableFuture ping(String str, Route route); + /** {@inheritDoc} The command will be routed a random node. */ + CompletableFuture clientId(); + + /** {@inheritDoc} The command will be routed a random node. */ + CompletableFuture clientGetName(); + /** * Get the current connection id. * From 4f3f614c3ea15e872b74200c1c03b363ec098195 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 20 Feb 2024 14:39:53 -0800 Subject: [PATCH 4/6] Minor fixes. Signed-off-by: Yury-Fridlyand --- .../api/commands/ConnectionManagementClusterCommands.java | 2 +- .../integTest/src/test/java/glide/cluster/CommandTests.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java index b5e1f0d9ee..d363042c83 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java @@ -18,7 +18,7 @@ public interface ConnectionManagementClusterCommands extends ConnectionManagemen * @see redis.io for details. * @param route Routing configuration for the command. Client will route the command to the nodes * defined. - * @return Response from Redis containing a String with PONG. + * @return Response from Redis containing a String with "PONG". */ CompletableFuture ping(Route route); diff --git a/java/integTest/src/test/java/glide/cluster/CommandTests.java b/java/integTest/src/test/java/glide/cluster/CommandTests.java index 4c82bc74c5..9ef4fe50bd 100644 --- a/java/integTest/src/test/java/glide/cluster/CommandTests.java +++ b/java/integTest/src/test/java/glide/cluster/CommandTests.java @@ -277,7 +277,11 @@ public void clientId() { var newClientId = newClient.clientId().get(); - assertTrue(currentId < newClientId); + assertTrue( + currentId < newClientId, + String.format( + "New client got ID smaller or equal that the old one. New ID : %d, old ID : %d", + newClientId, currentId)); } } From 88649d9cc0eb79815b6e0d6fb76f41d7c00c1238 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 20 Feb 2024 17:37:47 -0800 Subject: [PATCH 5/6] javajavadocdoc Signed-off-by: Yury-Fridlyand --- .../ConnectionManagementBaseCommands.java | 10 ++++ .../ConnectionManagementClusterCommands.java | 51 +++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java index 36b6fe6957..0eeaaccddc 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java @@ -33,6 +33,11 @@ public interface ConnectionManagementBaseCommands { * * @see redis.io for details. * @return The id of the client. + * @example + *
+     * long id = client.clientId().get();
+     * assert id > 0
+     * 
*/ CompletableFuture clientId(); @@ -42,6 +47,11 @@ public interface ConnectionManagementBaseCommands { * @see redis.io for details. * @return The name of the client connection as a string if a name is set, or null if * no name is assigned. + * @example + *
+     * String clientName = client.clientGetName().get();
+     * assert clientName != null
+     * 
*/ CompletableFuture clientGetName(); } diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java index d363042c83..79d7aeefd7 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java @@ -10,7 +10,7 @@ * * @see Connection Management Commands */ -public interface ConnectionManagementClusterCommands extends ConnectionManagementBaseCommands { +public interface ConnectionManagementClusterCommands { /** * Ping the Redis server. @@ -34,10 +34,33 @@ public interface ConnectionManagementClusterCommands extends ConnectionManagemen */ CompletableFuture ping(String str, Route route); - /** {@inheritDoc} The command will be routed a random node. */ + /** + * Get the current connection id.
+ * The command will be routed a random node. + * + * @see redis.io for details. + * @return The id of the client. + * @example + *
+     * long id = client.clientId().get();
+     * assert id > 0
+     * 
+ */ CompletableFuture clientId(); - /** {@inheritDoc} The command will be routed a random node. */ + /** + * Get the name of the current connection.
+ * The command will be routed a random node. + * + * @see redis.io for details. + * @return The name of the client connection as a string if a name is set, or null if + * no name is assigned. + * @example + *
+     * String clientName = client.clientGetName().get();
+     * assert clientName != null
+     * 
+ */ CompletableFuture clientGetName(); /** @@ -49,6 +72,17 @@ public interface ConnectionManagementClusterCommands extends ConnectionManagemen * @return A {@link ClusterValue} which holds a single value if single node route is used or a * dictionary where each address is the key and its corresponding node response is the value. * The value is the id of the client on that node. + * @example + *
+     * long id = client.clientId(new SlotIdRoute(...)).get().getSingleValue();
+     * assert id > 0
+     * 
+ * + * @example + *
+     * Map<String, Long> idPerNode = client.clientId(ALL_NODES).get().getMultiValue();
+     * assert idPerNode.get("<node 1 address>") > 0
+     * 
*/ CompletableFuture> clientId(Route route); @@ -62,6 +96,17 @@ public interface ConnectionManagementClusterCommands extends ConnectionManagemen * dictionary where each address is the key and its corresponding node response is the value. * The value is the name of the client connection as a string if a name is set, or null if no * name is assigned. + * @example + *
+     * String clientName = client.clientGetName(new SlotIdRoute(...)).get().getSingleValue();
+     * assert clientName != null
+     * 
+ * + * @example + *
+     * Map<String, String> clientNamePerNode = client.clientGetName(ALL_NODES).get().getMultiValue();
+     * assert clientNamePerNode.get("<node 1 address>") != null
+     * 
*/ CompletableFuture> clientGetName(Route route); } From 7d6c220244d9391cb6a279ae53d008c726c9faa7 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Wed, 21 Feb 2024 10:06:01 -0800 Subject: [PATCH 6/6] tense Signed-off-by: Yury-Fridlyand --- .../java/glide/api/RedisClusterClient.java | 10 +++--- .../ConnectionManagementBaseCommands.java | 4 +-- .../ConnectionManagementClusterCommands.java | 36 +++++++++---------- .../test/java/glide/cluster/CommandTests.java | 20 ++--------- 4 files changed, 27 insertions(+), 43 deletions(-) diff --git a/java/client/src/main/java/glide/api/RedisClusterClient.java b/java/client/src/main/java/glide/api/RedisClusterClient.java index 028c3a566a..7aeb762af3 100644 --- a/java/client/src/main/java/glide/api/RedisClusterClient.java +++ b/java/client/src/main/java/glide/api/RedisClusterClient.java @@ -141,11 +141,6 @@ public CompletableFuture clientId() { return super.clientId(); } - @Override - public CompletableFuture clientGetName() { - return super.clientGetName(); - } - @Override public CompletableFuture> clientId(@NonNull Route route) { return commandManager.submitNewCommand( @@ -158,6 +153,11 @@ public CompletableFuture> clientId(@NonNull Route route) { : ClusterValue.of(handleMapResponse(response))); } + @Override + public CompletableFuture clientGetName() { + return super.clientGetName(); + } + @Override public CompletableFuture> clientGetName(@NonNull Route route) { return commandManager.submitNewCommand( diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java index 0eeaaccddc..ebda8aa6b0 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementBaseCommands.java @@ -29,7 +29,7 @@ public interface ConnectionManagementBaseCommands { CompletableFuture ping(String str); /** - * Get the current connection id. + * Gets the current connection id. * * @see redis.io for details. * @return The id of the client. @@ -42,7 +42,7 @@ public interface ConnectionManagementBaseCommands { CompletableFuture clientId(); /** - * Get the name of the current connection. + * Gets the name of the current connection. * * @see redis.io for details. * @return The name of the client connection as a string if a name is set, or null if diff --git a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java index 79d7aeefd7..683fb4c8c5 100644 --- a/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java +++ b/java/client/src/main/java/glide/api/commands/ConnectionManagementClusterCommands.java @@ -35,7 +35,7 @@ public interface ConnectionManagementClusterCommands { CompletableFuture ping(String str, Route route); /** - * Get the current connection id.
+ * Gets the current connection id.
* The command will be routed a random node. * * @see redis.io for details. @@ -49,22 +49,7 @@ public interface ConnectionManagementClusterCommands { CompletableFuture clientId(); /** - * Get the name of the current connection.
- * The command will be routed a random node. - * - * @see redis.io for details. - * @return The name of the client connection as a string if a name is set, or null if - * no name is assigned. - * @example - *
-     * String clientName = client.clientGetName().get();
-     * assert clientName != null
-     * 
- */ - CompletableFuture clientGetName(); - - /** - * Get the current connection id. + * Gets the current connection id. * * @see redis.io for details. * @param route Routing configuration for the command. Client will route the command to the nodes @@ -87,7 +72,22 @@ public interface ConnectionManagementClusterCommands { CompletableFuture> clientId(Route route); /** - * Get the name of the current connection. + * Gets the name of the current connection.
+ * The command will be routed a random node. + * + * @see redis.io for details. + * @return The name of the client connection as a string if a name is set, or null if + * no name is assigned. + * @example + *
+     * String clientName = client.clientGetName().get();
+     * assert clientName != null
+     * 
+ */ + CompletableFuture clientGetName(); + + /** + * Gets the name of the current connection. * * @see redis.io for details. * @param route Routing configuration for the command. Client will route the command to the nodes diff --git a/java/integTest/src/test/java/glide/cluster/CommandTests.java b/java/integTest/src/test/java/glide/cluster/CommandTests.java index 9ef4fe50bd..4d719aa5b0 100644 --- a/java/integTest/src/test/java/glide/cluster/CommandTests.java +++ b/java/integTest/src/test/java/glide/cluster/CommandTests.java @@ -265,24 +265,8 @@ public void info_with_multi_node_route_and_options() { @Test @SneakyThrows public void clientId() { - var currentId = clusterClient.clientId().get(); - - try (var newClient = - RedisClusterClient.CreateClient( - RedisClusterClientConfiguration.builder() - .address(NodeAddress.builder().port(CLUSTER_PORTS[0]).build()) - .requestTimeout(5000) - .build()) - .get()) { - - var newClientId = newClient.clientId().get(); - - assertTrue( - currentId < newClientId, - String.format( - "New client got ID smaller or equal that the old one. New ID : %d, old ID : %d", - newClientId, currentId)); - } + var id = clusterClient.clientId().get(); + assertTrue(id > 0); } @Test