forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Java: Add transaction requests for standalone and cluster-mode #70
Closed
acarbonetto
wants to merge
26
commits into
java/integ_acarbo_api_transactions
from
java/dev_acarbo_api_transactions
+1,815
−234
Closed
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f296c00
Add cluster client, request routes configuration and support for bulk…
Yury-Fridlyand ef78f40
Add cluster client and routes support for cluster client.
Yury-Fridlyand 3fac54b
Address PR feedback and add tests.
Yury-Fridlyand 156765b
Add transactions for single and multi-cluster clients
acarbonetto ec3a76a
Fix unit tests
acarbonetto 6d308d2
Add Transactions on top of cluster mode
acarbonetto 1ea0060
Address PR feedback.
Yury-Fridlyand e9b4947
Add BaseTransaction
acarbonetto 5a62abc
Merge branch 'java/integ_yuryf_cluster_bulk_resp' into java/dev_acarb…
acarbonetto 80484ed
Documentation fixes
acarbonetto 65d6e17
Move protobuf build calls back to command manager
acarbonetto fa3713e
Update tests
acarbonetto 8f33d2b
Clean up tests
acarbonetto a7bf0a3
Change return type of info() to String
acarbonetto 4e4870c
Update the javadocs
acarbonetto 49ed65e
Update the javadocs
acarbonetto dcbaec4
Spotless
acarbonetto 4940950
Updates for comments
acarbonetto 87ec173
Move RequestType to it's own class
acarbonetto 55554f0
Update javadoc @Returns
acarbonetto 43ec3d8
Clean up test
acarbonetto 8eb9ea2
Merge branch 'java/integ_acarbo_api_transactions' into java/dev_acarb…
acarbonetto 825c1f7
Fix merge
acarbonetto e3fa7fa
Apply more javadoc changes; minor review comments
acarbonetto 5a96e65
Fix unit tests
acarbonetto 9c0ab6c
Apply review comments
acarbonetto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.api; | ||
|
||
import static glide.managers.RequestType.CUSTOM_COMMAND; | ||
import static glide.managers.RequestType.INFO; | ||
|
||
import glide.api.commands.ClusterBaseCommands; | ||
import glide.api.commands.ClusterServerCommands; | ||
import glide.api.models.ClusterTransaction; | ||
import glide.api.models.ClusterValue; | ||
import glide.api.models.commands.InfoOptions; | ||
import glide.api.models.configuration.RedisClusterClientConfiguration; | ||
import glide.api.models.configuration.RequestRoutingConfiguration.Route; | ||
import glide.connectors.handlers.ChannelHandler; | ||
import glide.managers.CommandManager; | ||
import glide.managers.ConnectionManager; | ||
import glide.managers.models.Command; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Async (non-blocking) client for Redis in Cluster mode. Use {@link #CreateClient} to request a | ||
* client to Redis. | ||
*/ | ||
public class RedisClusterClient extends BaseClient implements ClusterBaseCommands { | ||
public class RedisClusterClient extends BaseClient | ||
implements ClusterBaseCommands, ClusterServerCommands { | ||
|
||
protected RedisClusterClient(ConnectionManager connectionManager, CommandManager commandManager) { | ||
super(connectionManager, commandManager); | ||
|
@@ -25,37 +33,94 @@ protected RedisClusterClient(ConnectionManager connectionManager, CommandManager | |
* Async request for an async (non-blocking) Redis client in Cluster mode. | ||
* | ||
* @param config Redis cluster client Configuration | ||
* @return a Future to connect and return a ClusterClient | ||
* @return A Future to connect and return a RedisClusterClient | ||
*/ | ||
public static CompletableFuture<RedisClusterClient> CreateClient( | ||
RedisClusterClientConfiguration config) { | ||
return CreateClient(config, RedisClusterClient::new); | ||
try { | ||
ChannelHandler channelHandler = buildChannelHandler(); | ||
ConnectionManager connectionManager = buildConnectionManager(channelHandler); | ||
CommandManager commandManager = buildCommandManager(channelHandler); | ||
// TODO: Support exception throwing, including interrupted exceptions | ||
return connectionManager | ||
.connectToRedis(config) | ||
.thenApply(ignored -> new RedisClusterClient(connectionManager, commandManager)); | ||
} catch (InterruptedException e) { | ||
// Something bad happened while we were establishing netty connection to UDS | ||
var future = new CompletableFuture<RedisClusterClient>(); | ||
future.completeExceptionally(e); | ||
return future; | ||
} | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ClusterValue<Object>> customCommand(String[] args) { | ||
Command command = | ||
Command.builder().requestType(Command.RequestType.CUSTOM_COMMAND).arguments(args).build(); | ||
// TODO if a command returns a map as a single value, ClusterValue misleads user | ||
return commandManager.submitNewCommand( | ||
command, response -> ClusterValue.of(handleObjectResponse(response))); | ||
CUSTOM_COMMAND, | ||
args, | ||
Optional.empty(), | ||
response -> ClusterValue.of(handleObjectResponse(response))); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public CompletableFuture<ClusterValue<Object>> customCommand(String[] args, Route route) { | ||
Command command = | ||
Command.builder() | ||
.requestType(Command.RequestType.CUSTOM_COMMAND) | ||
.arguments(args) | ||
.route(route) | ||
.build(); | ||
|
||
return commandManager.submitNewCommand( | ||
command, | ||
CUSTOM_COMMAND, | ||
args, | ||
Optional.ofNullable(route), | ||
response -> | ||
route.isSingleNodeRoute() | ||
? ClusterValue.ofSingleValue(handleObjectResponse(response)) | ||
: ClusterValue.ofMultiValue((Map<String, Object>) handleObjectResponse(response))); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Object[]> exec(ClusterTransaction transaction) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to test this:
|
||
return commandManager.submitNewCommand( | ||
transaction, Optional.empty(), this::handleArrayResponse); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Object[]> exec(ClusterTransaction transaction, Route route) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
return commandManager.submitNewCommand( | ||
transaction, Optional.ofNullable(route), this::handleArrayResponse); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ClusterValue<String>> info() { | ||
return commandManager.submitNewCommand( | ||
INFO, | ||
new String[0], | ||
Optional.empty(), | ||
response -> ClusterValue.of(handleStringResponse(response))); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ClusterValue<String>> info(Route route) { | ||
return commandManager.submitNewCommand( | ||
INFO, | ||
new String[0], | ||
Optional.ofNullable(route), | ||
response -> ClusterValue.of(handleStringResponse(response))); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ClusterValue<String>> info(InfoOptions options) { | ||
return commandManager.submitNewCommand( | ||
INFO, | ||
options.toArgs(), | ||
Optional.empty(), | ||
response -> ClusterValue.of(handleStringResponse(response))); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ClusterValue<String>> info(InfoOptions options, Route route) { | ||
return commandManager.submitNewCommand( | ||
INFO, | ||
options.toArgs(), | ||
Optional.ofNullable(route), | ||
response -> ClusterValue.of(handleStringResponse(response))); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you are not actually casting the keys in to strings with this (Map<String, Object>) , at runtime they will still remain as type Object not string. We may need to cast keys individually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will test this and update the examples in the PR description.