Skip to content

Commit

Permalink
Clean up merge
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Jan 10, 2024
1 parent e361f58 commit a036bc6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 121 deletions.
117 changes: 4 additions & 113 deletions java/client/src/main/java/glide/api/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import response.ResponseOuterClass;

/**
Expand Down Expand Up @@ -98,7 +97,8 @@ public void close() throws ExecutionException {
* @param <T> Response value type
*/
protected <T> CompletableFuture exec(
Command command, RedisExceptionCheckedFunction<ResponseOuterClass.Response, T> responseHandler) {
Command command,
RedisExceptionCheckedFunction<ResponseOuterClass.Response, T> responseHandler) {
return commandManager.submitNewCommand(command, responseHandler);
}

Expand All @@ -109,116 +109,6 @@ protected <T> CompletableFuture exec(
* @param transaction with commands to be executed
* @return A CompletableFuture completed with the results from Redis
*/
@Override
public CompletableFuture<List<Object>> exec(Transaction transaction) {
// TODO: call commandManager.submitNewTransaction()
return exec(transaction, BaseCommands::handleTransactionResponse);
}

/**
* Execute a transaction by processing the queued commands. <br>
* See https://redis.io/topics/Transactions/ for details on Redis Transactions. <br>
*
* @param transaction with commands to be executed
* @param responseHandler handler responsible for assigning type to the list of response objects
* @return A CompletableFuture completed with the results from Redis
*/
protected CompletableFuture<List<Object>> exec(
Transaction transaction, Function<ResponseOuterClass.Response, List<Object>> responseHandler) {
// TODO: call commandManager.submitNewTransaction()
return new CompletableFuture<>();
}

/**
* Executes a single custom command, without checking inputs. Every part of the command, including
* subcommands, should be added as a separate value in args.
*
* @param args command and arguments for the custom command call
* @return CompletableFuture with the response
*/
public CompletableFuture<Object> customCommand(String[] args) {
Command command =
Command.builder().requestType(Command.RequestType.CUSTOM_COMMAND).arguments(args).build();
return exec(command, BaseCommands::handleObjectResponse);
}

/**
* Get the value associated with the given key, or null if no such value exists. See
* https://redis.io/commands/set/ for details.
*
* @param key - The key to retrieve from the database.
* @return If `key` exists, returns the value of `key` as a string. Otherwise, return null
*/
public CompletableFuture<String> get(String key) {
Command command =
Command.builder()
.requestType(Command.RequestType.GET_STRING)
.arguments(new String[] {key})
.build();
return exec(command, StringCommands::handleStringResponse);
}

/**
* Set the given key with the given value. Return value is dependent on the passed options. See
* https://redis.io/commands/set/ for details.
*
* @param key - The key to store.
* @param value - The value to store with the given key.
* @return null
*/
public CompletableFuture<Void> set(String key, String value) {
Command command =
Command.builder()
.requestType(Command.RequestType.SET_STRING)
.arguments(new String[] {key, value})
.build();
return exec(command, VoidCommands::handleVoidResponse);
}

/**
* Set the given key with the given value. Return value is dependent on the passed options. See
* https://redis.io/commands/set/ for details.
*
* @param key - The key to store.
* @param value - The value to store with the given key.
* @param options - The Set options
* @return string or null If value isn't set because of `onlyIfExists` or `onlyIfDoesNotExist`
* conditions, return null. If `returnOldValue` is set, return the old value as a string.
*/
public CompletableFuture<String> set(String key, String value, SetOptions options) {
LinkedList<String> args = new LinkedList<>();
args.add(key);
args.add(value);
args.addAll(SetOptions.createSetOptions(options));
Command command =
Command.builder()
.requestType(Command.RequestType.SET_STRING)
.arguments(args.toArray(new String[0]))
.build();
return exec(command, StringCommands::handleStringResponse);
}

/**
* Execute a single command against Redis. <br>
*
* @param command to be executed
* @param responseHandler handler responsible for assigning type to the response
* @return A CompletableFuture completed with the result from Redis
* @param <T> Response value type
*/
protected <T> CompletableFuture exec(
Command command, RedisExceptionCheckedFunction<Response, T> responseHandler) {
return commandManager.submitNewCommand(command, responseHandler);
}

/**
* Execute a transaction by processing the queued commands. <br>
* See https://redis.io/topics/Transactions/ for details on Redis Transactions. <br>
*
* @param transaction with commands to be executed
* @return A CompletableFuture completed with the results from Redis
*/
@Override
public CompletableFuture<List<Object>> exec(Transaction transaction) {
// TODO: call commandManager.submitNewTransaction()
return exec(transaction, BaseCommands::handleTransactionResponse);
Expand All @@ -233,7 +123,8 @@ public CompletableFuture<List<Object>> exec(Transaction transaction) {
* @return A CompletableFuture completed with the results from Redis
*/
protected CompletableFuture<List<Object>> exec(
Transaction transaction, Function<Response, List<Object>> responseHandler) {
Transaction transaction,
RedisExceptionCheckedFunction<ResponseOuterClass.Response, List<Object>> responseHandler) {
// TODO: call commandManager.submitNewTransaction()
return new CompletableFuture<>();
}
Expand Down
10 changes: 4 additions & 6 deletions java/client/src/main/java/glide/managers/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
import glide.api.commands.Command;
import glide.api.commands.RedisExceptionCheckedFunction;
import glide.connectors.handlers.ChannelHandler;
import glide.ffi.resolvers.RedisValueResolver;
import glide.models.RequestBuilder;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import lombok.RequiredArgsConstructor;
import redis_request.RedisRequestOuterClass.RequestType;
import response.ResponseOuterClass.Response;

/**
Expand Down Expand Up @@ -61,11 +57,13 @@ private redis_request.RedisRequestOuterClass.RedisRequest.Builder prepareRedisRe
.build())
.setRoute( // set route
redis_request.RedisRequestOuterClass.Routes.newBuilder()
.setSimpleRoutes(redis_request.RedisRequestOuterClass.SimpleRoutes.AllNodes) // set route type
.setSimpleRoutes(
redis_request.RedisRequestOuterClass.SimpleRoutes.AllNodes) // set route type
.build());
}

private redis_request.RedisRequestOuterClass.RequestType mapRequestTypes(Command.RequestType inType) {
private redis_request.RedisRequestOuterClass.RequestType mapRequestTypes(
Command.RequestType inType) {
switch (inType) {
case CUSTOM_COMMAND:
return redis_request.RedisRequestOuterClass.RequestType.CustomCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ public void DoubleConnection_successfullyReturns()
// setup
RedisClientConfiguration redisClientConfiguration = RedisClientConfiguration.builder().build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Response response = Response.newBuilder().build();
Response response = Response.newBuilder()
.setConstantResponse(ResponseOuterClass.ConstantResponse.OK).build();
completedFuture.complete(response);

// execute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public void onConnection_emptyResponse_throwsRuntimeException() {
// setup
RedisClientConfiguration redisClientConfiguration = RedisClientConfiguration.builder().build();
CompletableFuture<Response> completedFuture = new CompletableFuture<>();
Response response = Response.newBuilder().build();
Response response = Response.newBuilder()
.setConstantResponse(ResponseOuterClass.ConstantResponse.OK).build();
completedFuture.complete(response);

// execute
Expand Down

0 comments on commit a036bc6

Please sign in to comment.