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 93cfc82
Show file tree
Hide file tree
Showing 27 changed files with 16,812 additions and 17,044 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 @@ -3,17 +3,18 @@

import static java.util.concurrent.TimeUnit.SECONDS;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

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;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

/** A Glide client with async capabilities */
public class GlideAsyncClient implements AsyncClient<String> {
Expand All @@ -23,34 +24,32 @@ public class GlideAsyncClient implements AsyncClient<String> {
public void connectToRedis(ConnectionSettings connectionSettings) {

if (connectionSettings.clusterMode) {
RedisClusterClientConfiguration config =
RedisClusterClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
.port(connectionSettings.port)
.build())
.useTLS(connectionSettings.useSsl)
.build();
GlideClusterClientConfiguration config = GlideClusterClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
.port(connectionSettings.port)
.build())
.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()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
.port(connectionSettings.port)
.build())
.useTLS(connectionSettings.useSsl)
.build();
GlideClientConfiguration config = GlideClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
.port(connectionSettings.port)
.build())
.useTLS(connectionSettings.useSsl)
.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
800 changes: 352 additions & 448 deletions java/client/src/main/java/glide/api/BaseClient.java

Large diffs are not rendered by default.

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 @@ -42,6 +40,12 @@
import static redis_request.RedisRequestOuterClass.RequestType.Time;
import static redis_request.RedisRequestOuterClass.RequestType.UnWatch;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import org.apache.commons.lang3.ArrayUtils;

import glide.api.commands.ConnectionManagementCommands;
import glide.api.commands.GenericCommands;
import glide.api.commands.ScriptingAndFunctionsCommands;
Expand All @@ -53,39 +57,36 @@
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;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import lombok.NonNull;
import org.apache.commons.lang3.ArrayUtils;

/**
* Async (non-blocking) client for Redis in Standalone mode. Use {@link #CreateClient} to request a
* 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 {
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 All @@ -106,7 +107,7 @@ public CompletableFuture<String> ping() {
@Override
public CompletableFuture<String> ping(@NonNull String message) {
return commandManager.submitNewCommand(
Ping, new String[] {message}, this::handleStringResponse);
Ping, new String[] { message }, this::handleStringResponse);
}

@Override
Expand All @@ -122,7 +123,7 @@ public CompletableFuture<String> info(@NonNull InfoOptions options) {
@Override
public CompletableFuture<String> select(long index) {
return commandManager.submitNewCommand(
Select, new String[] {Long.toString(index)}, this::handleStringResponse);
Select, new String[] { Long.toString(index) }, this::handleStringResponse);
}

@Override
Expand Down Expand Up @@ -162,7 +163,7 @@ public CompletableFuture<String> configSet(@NonNull Map<String, String> paramete
@Override
public CompletableFuture<String> echo(@NonNull String message) {
return commandManager.submitNewCommand(
Echo, new String[] {message}, this::handleStringResponse);
Echo, new String[] { message }, this::handleStringResponse);
}

@Override
Expand All @@ -184,7 +185,7 @@ public CompletableFuture<String> flushall() {
@Override
public CompletableFuture<String> flushall(@NonNull FlushMode mode) {
return commandManager.submitNewCommand(
FlushAll, new String[] {mode.toString()}, this::handleStringResponse);
FlushAll, new String[] { mode.toString() }, this::handleStringResponse);
}

@Override
Expand All @@ -195,7 +196,7 @@ public CompletableFuture<String> flushdb() {
@Override
public CompletableFuture<String> flushdb(@NonNull FlushMode mode) {
return commandManager.submitNewCommand(
FlushDB, new String[] {mode.toString()}, this::handleStringResponse);
FlushDB, new String[] { mode.toString() }, this::handleStringResponse);
}

@Override
Expand All @@ -205,25 +206,23 @@ public CompletableFuture<String> lolwut() {

@Override
public CompletableFuture<String> lolwut(int @NonNull [] parameters) {
String[] arguments =
Arrays.stream(parameters).mapToObj(Integer::toString).toArray(String[]::new);
String[] arguments = Arrays.stream(parameters).mapToObj(Integer::toString).toArray(String[]::new);
return commandManager.submitNewCommand(Lolwut, arguments, this::handleStringResponse);
}

@Override
public CompletableFuture<String> lolwut(int version) {
return commandManager.submitNewCommand(
Lolwut,
new String[] {VERSION_REDIS_API, Integer.toString(version)},
new String[] { VERSION_REDIS_API, Integer.toString(version) },
this::handleStringResponse);
}

@Override
public CompletableFuture<String> lolwut(int version, int @NonNull [] parameters) {
String[] arguments =
concatenateArrays(
new String[] {VERSION_REDIS_API, Integer.toString(version)},
Arrays.stream(parameters).mapToObj(Integer::toString).toArray(String[]::new));
String[] arguments = concatenateArrays(
new String[] { VERSION_REDIS_API, Integer.toString(version) },
Arrays.stream(parameters).mapToObj(Integer::toString).toArray(String[]::new));
return commandManager.submitNewCommand(Lolwut, arguments, this::handleStringResponse);
}

Expand All @@ -234,28 +233,27 @@ public CompletableFuture<Long> dbsize() {

@Override
public CompletableFuture<String> functionLoad(@NonNull String libraryCode, boolean replace) {
String[] arguments =
replace ? new String[] {REPLACE.toString(), libraryCode} : new String[] {libraryCode};
String[] arguments = replace ? new String[] { REPLACE.toString(), libraryCode } : new String[] { libraryCode };
return commandManager.submitNewCommand(FunctionLoad, arguments, this::handleStringResponse);
}

@Override
public CompletableFuture<Boolean> move(@NonNull String key, long dbIndex) {
return commandManager.submitNewCommand(
Move, new String[] {key, Long.toString(dbIndex)}, this::handleBooleanResponse);
Move, new String[] { key, Long.toString(dbIndex) }, this::handleBooleanResponse);
}

@Override
public CompletableFuture<Boolean> move(@NonNull GlideString key, long dbIndex) {
return commandManager.submitNewCommand(
Move, new GlideString[] {key, gs(Long.toString(dbIndex))}, this::handleBooleanResponse);
Move, new GlideString[] { key, gs(Long.toString(dbIndex)) }, this::handleBooleanResponse);
}

@Override
public CompletableFuture<Map<String, Object>[]> functionList(boolean withCode) {
return commandManager.submitNewCommand(
FunctionList,
withCode ? new String[] {WITH_CODE_REDIS_API} : new String[0],
withCode ? new String[] { WITH_CODE_REDIS_API } : new String[0],
response -> handleFunctionListResponse(handleArrayResponse(response)));
}

Expand All @@ -265,8 +263,8 @@ public CompletableFuture<Map<String, Object>[]> functionList(
return commandManager.submitNewCommand(
FunctionList,
withCode
? new String[] {LIBRARY_NAME_REDIS_API, libNamePattern, WITH_CODE_REDIS_API}
: new String[] {LIBRARY_NAME_REDIS_API, libNamePattern},
? new String[] { LIBRARY_NAME_REDIS_API, libNamePattern, WITH_CODE_REDIS_API }
: new String[] { LIBRARY_NAME_REDIS_API, libNamePattern },
response -> handleFunctionListResponse(handleArrayResponse(response)));
}

Expand All @@ -279,13 +277,13 @@ public CompletableFuture<String> functionFlush() {
@Override
public CompletableFuture<String> functionFlush(@NonNull FlushMode mode) {
return commandManager.submitNewCommand(
FunctionFlush, new String[] {mode.toString()}, this::handleStringResponse);
FunctionFlush, new String[] { mode.toString() }, this::handleStringResponse);
}

@Override
public CompletableFuture<String> functionDelete(@NonNull String libName) {
return commandManager.submitNewCommand(
FunctionDelete, new String[] {libName}, this::handleStringResponse);
FunctionDelete, new String[] { libName }, this::handleStringResponse);
}

@Override
Expand All @@ -297,15 +295,15 @@ public CompletableFuture<byte[]> functionDump() {
@Override
public CompletableFuture<String> functionRestore(byte @NonNull [] payload) {
return commandManager.submitNewCommand(
FunctionRestore, new GlideString[] {gs(payload)}, this::handleStringResponse);
FunctionRestore, new GlideString[] { gs(payload) }, this::handleStringResponse);
}

@Override
public CompletableFuture<String> functionRestore(
byte @NonNull [] payload, @NonNull FunctionRestorePolicy policy) {
return commandManager.submitNewCommand(
FunctionRestore,
new GlideString[] {gs(payload), gs(policy.toString())},
new GlideString[] { gs(payload), gs(policy.toString()) },
this::handleStringResponse);
}

Expand All @@ -322,16 +320,14 @@ public CompletableFuture<Object> fcallReadOnly(@NonNull String function) {
@Override
public CompletableFuture<Boolean> copy(
@NonNull String source, @NonNull String destination, long destinationDB) {
String[] arguments =
new String[] {source, destination, DB_REDIS_API, Long.toString(destinationDB)};
String[] arguments = new String[] { source, destination, DB_REDIS_API, Long.toString(destinationDB) };
return commandManager.submitNewCommand(Copy, arguments, this::handleBooleanResponse);
}

@Override
public CompletableFuture<Boolean> copy(
@NonNull String source, @NonNull String destination, long destinationDB, boolean replace) {
String[] arguments =
new String[] {source, destination, DB_REDIS_API, Long.toString(destinationDB)};
String[] arguments = new String[] { source, destination, DB_REDIS_API, Long.toString(destinationDB) };
if (replace) {
arguments = ArrayUtils.add(arguments, REPLACE_REDIS_API);
}
Expand Down Expand Up @@ -382,9 +378,8 @@ public CompletableFuture<String[]> sortReadOnly(
@Override
public CompletableFuture<Long> sortStore(
@NonNull String key, @NonNull String destination, @NonNull SortOptions sortOptions) {
String[] storeArguments = new String[] {STORE_COMMAND_STRING, destination};
String[] arguments =
concatenateArrays(new String[] {key}, sortOptions.toArgs(), storeArguments);
String[] storeArguments = new String[] { STORE_COMMAND_STRING, destination };
String[] arguments = concatenateArrays(new String[] { key }, sortOptions.toArgs(), storeArguments);
return commandManager.submitNewCommand(Sort, arguments, this::handleLongResponse);
}
}
Loading

0 comments on commit 93cfc82

Please sign in to comment.