Skip to content

Commit

Permalink
Clean up merge changes
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Jan 11, 2024
1 parent b4df5a2 commit cada9b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 123 deletions.
118 changes: 5 additions & 113 deletions java/client/src/main/java/glide/api/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Async (non-blocking) client for Redis in Standalone mode. Use {@link
* #CreateClient(RedisClientConfiguration)} to request a client to Redis.
*/
public class RedisClient extends BaseClient {
public class RedisClient extends BaseClient implements BaseCommands, VoidCommands, StringCommands {

/**
* Request an async (non-blocking) Redis client in Standalone mode.
Expand Down Expand Up @@ -68,7 +68,8 @@ protected RedisClient(ConnectionManager connectionManager, CommandManager comman
* @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 @@ -79,7 +80,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);
Expand All @@ -94,116 +94,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<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);
}

/**
* 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<Response, List<Object>> responseHandler) {
Transaction transaction,
Function<ResponseOuterClass.Response, List<Object>> responseHandler) {
// TODO: call commandManager.submitNewTransaction()
return new CompletableFuture<>();
}
Expand Down
21 changes: 12 additions & 9 deletions java/client/src/test/java/glide/handlers/ReadHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public void teardown() {

@Test
public void readHandlerRead_testInboundProtobufMessages() {
ResponseOuterClass.Response msg = ResponseOuterClass.Response.newBuilder()
.setConstantResponse(ResponseOuterClass.ConstantResponse.OK)
.build();
ResponseOuterClass.Response msg =
ResponseOuterClass.Response.newBuilder()
.setConstantResponse(ResponseOuterClass.ConstantResponse.OK)
.build();

assertTrue(embeddedChannel.writeInbound(msg, msg, msg));
assertTrue(embeddedChannel.finish());
Expand All @@ -51,19 +52,21 @@ public void readHandlerRead_testInboundProtobufMessages_invalidMessage() {

String invalidMsg = "Invalid";

Exception e = assertThrows(Exception.class, () -> embeddedChannel.writeInbound(invalidMsg, invalidMsg, invalidMsg));
Exception e =
assertThrows(
Exception.class,
() -> embeddedChannel.writeInbound(invalidMsg, invalidMsg, invalidMsg));
assertEquals("Unexpected message in socket", e.getMessage());

verify(dispatcher, times(0)).completeRequest(any());

ResponseOuterClass.Response msg = ResponseOuterClass.Response.newBuilder()
.setConstantResponse(ResponseOuterClass.ConstantResponse.OK)
.build();
ResponseOuterClass.Response msg =
ResponseOuterClass.Response.newBuilder()
.setConstantResponse(ResponseOuterClass.ConstantResponse.OK)
.build();
assertTrue(embeddedChannel.writeInbound(msg));
assertTrue(embeddedChannel.finish());

verify(dispatcher, times(1)).completeRequest(msg);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ public void CheckRedisResponse_ClosingError_throwsRuntimeException() {
assertTrue(exception.getCause() instanceof RuntimeException);
}


@SneakyThrows
@Test
public void CloseConnection_closesChannels() {
Expand Down

0 comments on commit cada9b7

Please sign in to comment.