Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support transactions #65

Conversation

Yury-Fridlyand
Copy link

@Yury-Fridlyand Yury-Fridlyand commented Jan 18, 2024

Depends on:

    var regularClient =
        RedisClient.CreateClient(
                RedisClientConfiguration.builder()
                    .address(NodeAddress.builder().build())
                    .requestTimeout(3000)
                    .build())

    var res =
        regularClient
            .customTransaction(new String[][] {{"set", "kkk", "vvv"}, {"get", "kkk"}})
            .get();

returns Object[2] with 2 strings: OK and vvv.

Signed-off-by: Yury-Fridlyand <[email protected]>
Signed-off-by: Yury-Fridlyand <[email protected]>
@Yury-Fridlyand Yury-Fridlyand marked this pull request as draft January 18, 2024 18:43
Copy link

@acarbonetto acarbonetto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to expect users to create a 2D array of Strings

* @param args arguments for the custom command
* @return a CompletableFuture with response result from Redis
*/
CompletableFuture<Object[]> customTransaction(String[][] args);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about exposing?

CompletableFuture<Object[]> customTransaction(Transaction transaction);

This is what the node client does: https://github.com/Bit-Quill/glide-for-redis/blob/46f831c5d2b31a667f7d7c53035b99e8b3851f26/node/src/RedisClient.ts#L98

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may have to create a Transactions class that implements BaseCommands that adds the transaction calls to the list.
Maybe also a ClusterTransactions class that implements BaseClusterCommands too...

reference: https://github.com/Bit-Quill/glide-for-redis/blob/main/node/src/Transaction.ts#L72

@@ -30,7 +32,7 @@ public static CompletableFuture<RedisClient> CreateClient(RedisClientConfigurati
// TODO: Support exception throwing, including interrupted exceptions
return connectionManager
.connectToRedis(config)
.thenApply(ignore -> new RedisClient(connectionManager, commandManager));
.thenApplyAsync(ignore -> new RedisClient(connectionManager, commandManager));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not run it in the same thread?

var transactionBuilder = Transaction.newBuilder();
for (var command : transaction) {
transactionBuilder.addCommands(
prepareRedisCommand(command.getRequestType(), command.getArguments()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work routes? Each command gets a route, right?
I think the API.Command object can be used to pass that in, and there will be a third argument in prepareRedisCommand that takes a command.getRouteOption(), right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to protobuf - route set to the entire request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. That makes sense.

@Yury-Fridlyand Yury-Fridlyand deleted the java/dev_yuryf_transactions branch January 25, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants