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 6fd3fd1
Show file tree
Hide file tree
Showing 26 changed files with 341 additions and 329 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
71 changes: 9 additions & 62 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@

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.bitmap.BitFieldOptions.BitFieldReadOnlySubCommands;
import static glide.api.models.commands.bitmap.BitFieldOptions.BitFieldSubCommands;
import static glide.api.models.commands.bitmap.BitFieldOptions.createBitFieldArgs;
import static glide.ffi.resolvers.SocketListenerResolver.getSocket;
import static glide.utils.ArrayTransformUtils.castArray;
import static glide.utils.ArrayTransformUtils.castArrayofArrays;
import static glide.utils.ArrayTransformUtils.castMapOf2DArray;
import static glide.utils.ArrayTransformUtils.castMapOfArrays;
import static glide.utils.ArrayTransformUtils.concatenateArrays;
import static glide.utils.ArrayTransformUtils.convertMapToKeyValueStringArray;
import static glide.utils.ArrayTransformUtils.convertMapToValueKeyStringArray;
Expand Down Expand Up @@ -116,57 +111,6 @@
import static redis_request.RedisRequestOuterClass.RequestType.SRandMember;
import static redis_request.RedisRequestOuterClass.RequestType.SRem;
import static redis_request.RedisRequestOuterClass.RequestType.SUnion;
import static redis_request.RedisRequestOuterClass.RequestType.SUnionStore;
import static redis_request.RedisRequestOuterClass.RequestType.Set;
import static redis_request.RedisRequestOuterClass.RequestType.SetBit;
import static redis_request.RedisRequestOuterClass.RequestType.SetRange;
import static redis_request.RedisRequestOuterClass.RequestType.Sort;
import static redis_request.RedisRequestOuterClass.RequestType.SortReadOnly;
import static redis_request.RedisRequestOuterClass.RequestType.Strlen;
import static redis_request.RedisRequestOuterClass.RequestType.TTL;
import static redis_request.RedisRequestOuterClass.RequestType.Touch;
import static redis_request.RedisRequestOuterClass.RequestType.Type;
import static redis_request.RedisRequestOuterClass.RequestType.Unlink;
import static redis_request.RedisRequestOuterClass.RequestType.Watch;
import static redis_request.RedisRequestOuterClass.RequestType.XAck;
import static redis_request.RedisRequestOuterClass.RequestType.XAdd;
import static redis_request.RedisRequestOuterClass.RequestType.XDel;
import static redis_request.RedisRequestOuterClass.RequestType.XGroupCreate;
import static redis_request.RedisRequestOuterClass.RequestType.XGroupCreateConsumer;
import static redis_request.RedisRequestOuterClass.RequestType.XGroupDelConsumer;
import static redis_request.RedisRequestOuterClass.RequestType.XGroupDestroy;
import static redis_request.RedisRequestOuterClass.RequestType.XLen;
import static redis_request.RedisRequestOuterClass.RequestType.XRange;
import static redis_request.RedisRequestOuterClass.RequestType.XRead;
import static redis_request.RedisRequestOuterClass.RequestType.XReadGroup;
import static redis_request.RedisRequestOuterClass.RequestType.XRevRange;
import static redis_request.RedisRequestOuterClass.RequestType.XTrim;
import static redis_request.RedisRequestOuterClass.RequestType.ZAdd;
import static redis_request.RedisRequestOuterClass.RequestType.ZCard;
import static redis_request.RedisRequestOuterClass.RequestType.ZCount;
import static redis_request.RedisRequestOuterClass.RequestType.ZDiff;
import static redis_request.RedisRequestOuterClass.RequestType.ZDiffStore;
import static redis_request.RedisRequestOuterClass.RequestType.ZIncrBy;
import static redis_request.RedisRequestOuterClass.RequestType.ZInter;
import static redis_request.RedisRequestOuterClass.RequestType.ZInterCard;
import static redis_request.RedisRequestOuterClass.RequestType.ZInterStore;
import static redis_request.RedisRequestOuterClass.RequestType.ZLexCount;
import static redis_request.RedisRequestOuterClass.RequestType.ZMPop;
import static redis_request.RedisRequestOuterClass.RequestType.ZMScore;
import static redis_request.RedisRequestOuterClass.RequestType.ZPopMax;
import static redis_request.RedisRequestOuterClass.RequestType.ZPopMin;
import static redis_request.RedisRequestOuterClass.RequestType.ZRandMember;
import static redis_request.RedisRequestOuterClass.RequestType.ZRange;
import static redis_request.RedisRequestOuterClass.RequestType.ZRangeStore;
import static redis_request.RedisRequestOuterClass.RequestType.ZRank;
import static redis_request.RedisRequestOuterClass.RequestType.ZRem;
import static redis_request.RedisRequestOuterClass.RequestType.ZRemRangeByLex;
import static redis_request.RedisRequestOuterClass.RequestType.ZRemRangeByRank;
import static redis_request.RedisRequestOuterClass.RequestType.ZRemRangeByScore;
import static redis_request.RedisRequestOuterClass.RequestType.ZRevRank;
import static redis_request.RedisRequestOuterClass.RequestType.ZScore;
import static redis_request.RedisRequestOuterClass.RequestType.ZUnion;
import static redis_request.RedisRequestOuterClass.RequestType.ZUnionStore;

import glide.api.commands.BitmapBaseCommands;
import glide.api.commands.GenericBaseCommands;
Expand Down Expand Up @@ -200,6 +144,8 @@
import glide.api.models.commands.WeightAggregateOptions.KeyArray;
import glide.api.models.commands.WeightAggregateOptions.KeysOrWeightedKeys;
import glide.api.models.commands.ZAddOptions;
import glide.api.models.commands.bitmap.BitFieldOptions.BitFieldReadOnlySubCommands;
import glide.api.models.commands.bitmap.BitFieldOptions.BitFieldSubCommands;
import glide.api.models.commands.bitmap.BitmapIndexType;
import glide.api.models.commands.bitmap.BitwiseOperation;
import glide.api.models.commands.geospatial.GeoAddOptions;
Expand All @@ -222,6 +168,8 @@
import glide.managers.BaseCommandResponseResolver;
import glide.managers.CommandManager;
import glide.managers.ConnectionManager;
import glide.models.protobuf.response.ResponseOuterClass.ConstantResponse;
import glide.models.protobuf.response.ResponseOuterClass.Response;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
Expand All @@ -234,8 +182,6 @@
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.apache.commons.lang3.ArrayUtils;
import response.ResponseOuterClass.ConstantResponse;
import response.ResponseOuterClass.Response;

/** Base Client class for Redis */
@AllArgsConstructor
Expand Down Expand Up @@ -266,7 +212,7 @@ public abstract class BaseClient
* @param config Redis client Configuration.
* @param constructor Redis client constructor reference.
* @param <T> Client type.
* @return a Future to connect and return a RedisClient.
* @return a Future to connect and return a GlideClient.
*/
protected static <T> CompletableFuture<T> CreateClient(
BaseClientConfiguration config,
Expand Down Expand Up @@ -297,8 +243,8 @@ protected static <T> CompletableFuture<T> CreateClient(
* Closes this resource, relinquishing any underlying resources. This method is invoked
* automatically on objects managed by the try-with-resources statement.
*
* @see <a
* href="https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html#close--">AutoCloseable::close()</a>
* @see <a href=
* "https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html#close--">AutoCloseable::close()</a>
*/
@Override
public void close() throws ExecutionException {
Expand Down Expand Up @@ -2530,7 +2476,8 @@ public CompletableFuture<Set<String>> sunion(@NonNull String[] keys) {
return commandManager.submitNewCommand(SUnion, keys, this::handleSetResponse);
}

// Hack: convert all `byte[]` -> `GlideString`. Better doing it here in the Java realm
// Hack: convert all `byte[]` -> `GlideString`. Better doing it here in the Java
// realm
// rather than doing it in the Rust code using JNI calls (performance)
private Object convertByteArrayToGlideString(Object o) {
if (o == null) return o;
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 {}
Loading

0 comments on commit 6fd3fd1

Please sign in to comment.