Skip to content

Commit

Permalink
Java: Rename RedisClient, RedisClusterClient to GlideClient, GlideClu…
Browse files Browse the repository at this point in the history
…sterClient
  • Loading branch information
shohamazon committed Jun 26, 2024
1 parent fe08390 commit f080190
Show file tree
Hide file tree
Showing 24 changed files with 332 additions and 267 deletions.
4 changes: 2 additions & 2 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ Other useful gradle developer commands:
### Standalone Redis:

```java
import glide.api.RedisClient;
import glide.api.GlideClient;

RedisClient client = RedisClient.CreateClient().get();
GlideClient client = GlideClient.CreateClient().get();

CompletableFuture<String> setResponse = client.set("key", "foobar");
assert setResponse.get() == "OK" : "Failed on client.set("key", "foobar") request";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import static java.util.concurrent.TimeUnit.SECONDS;

import glide.api.BaseClient;
import glide.api.RedisClient;
import glide.api.RedisClusterClient;
import glide.api.GlideClient;
import glide.api.GlideClusterClient;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.RedisClientConfiguration;
import glide.api.models.configuration.RedisClusterClientConfiguration;
import glide.benchmarks.clients.AsyncClient;
import glide.benchmarks.utils.ConnectionSettings;
import java.util.concurrent.CompletableFuture;
Expand All @@ -23,8 +23,8 @@ public class GlideAsyncClient implements AsyncClient<String> {
public void connectToRedis(ConnectionSettings connectionSettings) {

if (connectionSettings.clusterMode) {
RedisClusterClientConfiguration config =
RedisClusterClientConfiguration.builder()
GlideClusterClientConfiguration config =
GlideClusterClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
Expand All @@ -33,14 +33,14 @@ public void connectToRedis(ConnectionSettings connectionSettings) {
.useTLS(connectionSettings.useSsl)
.build();
try {
redisClient = RedisClusterClient.CreateClient(config).get(10, SECONDS);
redisClient = GlideClusterClient.CreateClient(config).get(10, SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}

} else {
RedisClientConfiguration config =
RedisClientConfiguration.builder()
GlideClientConfiguration config =
GlideClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
Expand All @@ -50,7 +50,7 @@ public void connectToRedis(ConnectionSettings connectionSettings) {
.build();

try {
redisClient = RedisClient.CreateClient(config).get(10, SECONDS);
redisClient = GlideClient.CreateClient(config).get(10, SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

import static glide.api.models.GlideString.gs;
import static glide.api.models.commands.SortBaseOptions.STORE_COMMAND_STRING;
import static glide.api.models.commands.SortOptions.STORE_COMMAND_STRING;
import static glide.api.models.commands.function.FunctionListOptions.LIBRARY_NAME_REDIS_API;
import static glide.api.models.commands.function.FunctionListOptions.WITH_CODE_REDIS_API;
import static glide.api.models.commands.function.FunctionLoadOptions.REPLACE;
import static glide.utils.ArrayTransformUtils.castArray;
import static glide.utils.ArrayTransformUtils.concatenateArrays;
import static glide.utils.ArrayTransformUtils.convertMapToKeyValueStringArray;
import static redis_request.RedisRequestOuterClass.RequestType.ClientGetName;
Expand Down Expand Up @@ -53,7 +51,7 @@
import glide.api.models.commands.InfoOptions;
import glide.api.models.commands.SortOptions;
import glide.api.models.commands.function.FunctionRestorePolicy;
import glide.api.models.configuration.RedisClientConfiguration;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.managers.CommandManager;
import glide.managers.ConnectionManager;
import java.util.Arrays;
Expand All @@ -66,26 +64,26 @@
* Async (non-blocking) client for Redis in Standalone mode. Use {@link #CreateClient} to request a
* client to Redis.
*/
public class RedisClient extends BaseClient
public class GlideClient extends BaseClient
implements GenericCommands,
ServerManagementCommands,
ConnectionManagementCommands,
ScriptingAndFunctionsCommands,
TransactionsCommands {

protected RedisClient(ConnectionManager connectionManager, CommandManager commandManager) {
protected GlideClient(ConnectionManager connectionManager, CommandManager commandManager) {
super(connectionManager, commandManager);
}

/**
* Async request for an async (non-blocking) Redis client in Standalone mode.
*
* @param config Redis client Configuration
* @return A Future to connect and return a RedisClient
* @return A Future to connect and return a GlideClient
*/
public static CompletableFuture<RedisClient> CreateClient(
@NonNull RedisClientConfiguration config) {
return CreateClient(config, RedisClient::new);
public static CompletableFuture<GlideClient> CreateClient(
@NonNull GlideClientConfiguration config) {
return CreateClient(config, GlideClient::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import glide.api.models.commands.InfoOptions;
import glide.api.models.commands.SortClusterOptions;
import glide.api.models.commands.function.FunctionRestorePolicy;
import glide.api.models.configuration.RedisClusterClientConfiguration;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.RequestRoutingConfiguration.Route;
import glide.api.models.configuration.RequestRoutingConfiguration.SingleNodeRoute;
import glide.managers.CommandManager;
Expand All @@ -72,26 +72,26 @@
* Async (non-blocking) client for Redis in Cluster mode. Use {@link #CreateClient} to request a
* client to Redis.
*/
public class RedisClusterClient extends BaseClient
public class GlideClusterClient extends BaseClient
implements ConnectionManagementClusterCommands,
GenericClusterCommands,
ServerManagementClusterCommands,
ScriptingAndFunctionsClusterCommands,
TransactionsClusterCommands {

protected RedisClusterClient(ConnectionManager connectionManager, CommandManager commandManager) {
protected GlideClusterClient(ConnectionManager connectionManager, CommandManager commandManager) {
super(connectionManager, commandManager);
}

/**
* Async request for an async (non-blocking) Redis client in Cluster mode.
*
* @param config Redis cluster client Configuration
* @return A Future to connect and return a RedisClusterClient
* @return A Future to connect and return a GlideClusterClient
*/
public static CompletableFuture<RedisClusterClient> CreateClient(
@NonNull RedisClusterClientConfiguration config) {
return CreateClient(config, RedisClusterClient::new);
public static CompletableFuture<GlideClusterClient> CreateClient(
@NonNull GlideClusterClientConfiguration config) {
return CreateClient(config, GlideClusterClient::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.models.commands;

import glide.api.RedisClient;
import glide.api.RedisClusterClient;
import glide.api.GlideClient;
import glide.api.GlideClusterClient;
import glide.api.models.configuration.RequestRoutingConfiguration.Route;
import glide.api.models.configuration.RequestRoutingConfiguration.SingleNodeRoute;

Expand All @@ -11,15 +11,15 @@
* Defines flushing mode for:
*
* <ul>
* <li><code>FLUSHALL</code> command implemented by {@link RedisClient#flushall(FlushMode)},
* {@link RedisClusterClient#flushall(FlushMode)}, and {@link
* RedisClusterClient#flushall(FlushMode, SingleNodeRoute)}.
* <li><code>FLUSHDB</code> command implemented by {@link RedisClient#flushdb(FlushMode)}, {@link
* RedisClusterClient#flushdb(FlushMode)}, and {@link RedisClusterClient#flushdb(FlushMode,
* <li><code>FLUSHALL</code> command implemented by {@link GlideClient#flushall(FlushMode)},
* {@link GlideClusterClient#flushall(FlushMode)}, and {@link
* GlideClusterClient#flushall(FlushMode, SingleNodeRoute)}.
* <li><code>FLUSHDB</code> command implemented by {@link GlideClient#flushdb(FlushMode)}, {@link
* GlideClusterClient#flushdb(FlushMode)}, and {@link GlideClusterClient#flushdb(FlushMode,
* SingleNodeRoute)}.
* <li><code>FUNCTION FLUSH</code> command implemented by {@link
* RedisClient#functionFlush(FlushMode)}, {@link RedisClusterClient#functionFlush(FlushMode)},
* and {@link RedisClusterClient#functionFlush(FlushMode, Route)}.
* GlideClient#functionFlush(FlushMode)}, {@link GlideClusterClient#functionFlush(FlushMode)},
* and {@link GlideClusterClient#functionFlush(FlushMode, Route)}.
* </ul>
*
* @see <a href="https://valkey.io/commands/flushall/">flushall</a>, <a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import lombok.Getter;
import lombok.experimental.SuperBuilder;

/** Represents the configuration settings for a Standalone Redis client. */
/** Represents the configuration settings for a Standalone Glide client. */
@Getter
@SuperBuilder
public class RedisClientConfiguration extends BaseClientConfiguration {
public class GlideClientConfiguration extends BaseClientConfiguration {
/** Strategy used to determine how and when to reconnect, in case of connection failures. */
private final BackoffStrategy reconnectStrategy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
* values is used.
*/
@SuperBuilder
public class RedisClusterClientConfiguration extends BaseClientConfiguration {}
public class GlideClusterClientConfiguration extends BaseClientConfiguration {}
38 changes: 20 additions & 18 deletions java/client/src/main/java/glide/managers/ConnectionManager.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.managers;

import connection_request.ConnectionRequestOuterClass;
import connection_request.ConnectionRequestOuterClass.AuthenticationInfo;
import connection_request.ConnectionRequestOuterClass.ConnectionRequest;
import connection_request.ConnectionRequestOuterClass.TlsMode;
import glide.api.models.configuration.BaseClientConfiguration;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.ReadFrom;
import glide.api.models.configuration.RedisClientConfiguration;
import glide.api.models.configuration.RedisClusterClientConfiguration;
import glide.api.models.exceptions.ClosingException;
import glide.connectors.handlers.ChannelHandler;
import glide.models.protobuf.connection_request.ConnectionRequestOuterClass;
import glide.models.protobuf.connection_request.ConnectionRequestOuterClass.AuthenticationInfo;
import glide.models.protobuf.connection_request.ConnectionRequestOuterClass.ConnectionRequest;
import glide.models.protobuf.connection_request.ConnectionRequestOuterClass.TlsMode;
import glide.models.protobuf.response.ResponseOuterClass.Response;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import lombok.RequiredArgsConstructor;
import response.ResponseOuterClass.Response;

/**
* Service responsible for submitting connection requests to a socket channel handler and unpack
Expand All @@ -24,8 +24,9 @@
@RequiredArgsConstructor
public class ConnectionManager {

// TODO: consider making connection manager static, and moving the ChannelHandler to the
// RedisClient.
// TODO: consider making connection manager static, and moving the
// ChannelHandler to the
// GlideClient.

/** UDS connection representation. */
private final ChannelHandler channel;
Expand Down Expand Up @@ -66,13 +67,13 @@ private Response exceptionHandler(Throwable e) {
* @return ConnectionRequest protobuf message
*/
private ConnectionRequest createConnectionRequest(BaseClientConfiguration configuration) {
if (configuration instanceof RedisClusterClientConfiguration) {
return setupConnectionRequestBuilderRedisClusterClient(
(RedisClusterClientConfiguration) configuration)
if (configuration instanceof GlideClusterClientConfiguration) {
return setupConnectionRequestBuilderGlideClusterClient(
(GlideClusterClientConfiguration) configuration)
.build();
}

return setupConnectionRequestBuilderRedisClient((RedisClientConfiguration) configuration)
return setupConnectionRequestBuilderGlideClient((GlideClientConfiguration) configuration)
.build();
}

Expand Down Expand Up @@ -123,8 +124,8 @@ private ConnectionRequest.Builder setupConnectionRequestBuilderBaseConfiguration
*
* @param configuration Connection Request Configuration
*/
private ConnectionRequest.Builder setupConnectionRequestBuilderRedisClient(
RedisClientConfiguration configuration) {
private ConnectionRequest.Builder setupConnectionRequestBuilderGlideClient(
GlideClientConfiguration configuration) {
ConnectionRequest.Builder connectionRequestBuilder =
setupConnectionRequestBuilderBaseConfiguration(configuration);
connectionRequestBuilder.setClusterModeEnabled(false);
Expand All @@ -150,8 +151,8 @@ private ConnectionRequest.Builder setupConnectionRequestBuilderRedisClient(
* @param configuration
*/
private ConnectionRequestOuterClass.ConnectionRequest.Builder
setupConnectionRequestBuilderRedisClusterClient(
RedisClusterClientConfiguration configuration) {
setupConnectionRequestBuilderGlideClusterClient(
GlideClusterClientConfiguration configuration) {
ConnectionRequest.Builder connectionRequestBuilder =
setupConnectionRequestBuilderBaseConfiguration(configuration);
connectionRequestBuilder.setClusterModeEnabled(true);
Expand All @@ -175,7 +176,8 @@ private ConnectionRequestOuterClass.ReadFrom mapReadFromEnum(ReadFrom readFrom)

/** Check a response received from Glide. */
private Void checkGlideRsResponse(Response response) {
// Note: errors are already handled before in CallbackDispatcher, but we double-check
// Note: errors are already handled before in CallbackDispatcher, but we
// double-check
if (response.hasRequestError()) {
throwClosingError(
"Unhandled request error in response: " + response.getRequestError().getMessage());
Expand Down
Loading

0 comments on commit f080190

Please sign in to comment.