Skip to content

Commit

Permalink
Changed the API to support binary transaction (#1731)
Browse files Browse the repository at this point in the history
* Changed the API to support binary transaction

In addition, the following commands are modified to support it:

customCommand, echo, ping, del, get, getdel, getex, set, append, mget, mset, msetnx, incr, incrBy, incrByFloat, decr, decrBy, strlen, setrange
, getrange, hget, hset, hsetnx, hdel, hlen, hvals, hmget, spopCount

* Temporarily disable large-values tests

* ArgsBuilder now collects all arguments and returns `GlideString[]`
Restored large value tests
  • Loading branch information
eifrah-aws authored Jul 1, 2024
1 parent fbbcb17 commit 111de9f
Show file tree
Hide file tree
Showing 9 changed files with 630 additions and 441 deletions.
7 changes: 6 additions & 1 deletion java/client/src/main/java/glide/api/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ public CompletableFuture<Object> customCommand(@NonNull String[] args) {

@Override
public CompletableFuture<Object[]> exec(@NonNull Transaction transaction) {
return commandManager.submitNewTransaction(transaction, this::handleArrayOrNullResponse);
if (transaction.isBinarySafeOutput()) {
return commandManager.submitNewTransaction(
transaction, this::handleArrayOrNullResponseBinary);
} else {
return commandManager.submitNewTransaction(transaction, this::handleArrayOrNullResponse);
}
}

@Override
Expand Down
18 changes: 14 additions & 4 deletions java/client/src/main/java/glide/api/RedisClusterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,25 @@ protected ClusterValue<Object> handleCustomCommandResponse(Route route, Response

@Override
public CompletableFuture<Object[]> exec(@NonNull ClusterTransaction transaction) {
return commandManager.submitNewTransaction(
transaction, Optional.empty(), this::handleArrayOrNullResponse);
if (transaction.isBinarySafeOutput()) {
return commandManager.submitNewTransaction(
transaction, Optional.empty(), this::handleArrayOrNullResponseBinary);
} else {
return commandManager.submitNewTransaction(
transaction, Optional.empty(), this::handleArrayOrNullResponse);
}
}

@Override
public CompletableFuture<Object[]> exec(
@NonNull ClusterTransaction transaction, @NonNull SingleNodeRoute route) {
return commandManager.submitNewTransaction(
transaction, Optional.of(route), this::handleArrayOrNullResponse);
if (transaction.isBinarySafeOutput()) {
return commandManager.submitNewTransaction(
transaction, Optional.of(route), this::handleArrayOrNullResponseBinary);
} else {
return commandManager.submitNewTransaction(
transaction, Optional.of(route), this::handleArrayOrNullResponse);
}
}

@Override
Expand Down
40 changes: 40 additions & 0 deletions java/client/src/main/java/glide/api/models/ArgsBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.models;

import java.util.ArrayList;

/**
* Helper class for collecting arbitrary type of arguments and stores them as an array of
* GlideString
*/
public class ArgsBuilder {
ArrayList<GlideString> argumentsList = null;

public ArgsBuilder() {
argumentsList = new ArrayList<>();
}

public <ArgType> ArgsBuilder add(ArgType[] args) {
for (ArgType arg : args) {
argumentsList.add(GlideString.of(arg));
}

return this;
}

public <ArgType> ArgsBuilder add(ArgType arg) {
argumentsList.add(GlideString.of(arg));
return this;
}

public ArgsBuilder add(String[] args) {
for (String arg : args) {
argumentsList.add(GlideString.of(arg));
}
return this;
}

public GlideString[] toArray() {
return argumentsList.toArray(new GlideString[0]);
}
}
Loading

0 comments on commit 111de9f

Please sign in to comment.