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

Java: Add transaction commands #895

Merged

Conversation

acarbonetto
Copy link
Contributor

@acarbonetto acarbonetto commented Feb 2, 2024

Issue #, if available:

Description of changes:

Adds transactions for both standalone and cluster clients using the exec command: by passing a route (for cluster clients) and a pipeline of commands in a Transaction object. The object is then passed to Redis through the submitNewCommand(Transaction) call.

This PR is supposed for merge after #894

Examples:
// Transactions
Transaction standaloneTransaction = new Transaction()
    .ping()
    .set("key", "value")
    .get("key")
    .info();
Object[] transactionResult = client.exec(standaloneTransaction).get();

ClusterTransaction clusterTransaction = new ClusterTransaction()
    .ping()
    .set("key", "value")
    .get("key")
    .info();
ClusterValue[] transactionResult = clusterClient.exec(clusterTransaction, ALL_NODES).get();

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@acarbonetto acarbonetto requested a review from a team as a code owner February 2, 2024 05:47
@acarbonetto acarbonetto self-assigned this Feb 2, 2024
@acarbonetto acarbonetto added the java issues and fixes related to the java client label Feb 2, 2024
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

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

Please add

  1. IT
  2. protection for custom command vs empty args input

@ikolomi ikolomi self-requested a review February 5, 2024 10:28
@Getter
public abstract class BaseTransaction<T extends BaseTransaction<T>> {
/** Command class to send a single request to Redis. */
protected final Transaction.Builder transactionBuilder = Transaction.newBuilder();
Copy link
Contributor

Choose a reason for hiding this comment

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

You're using here protobuf's Transaction, and it reduces legibility. Please use ProtobufTransaction, or a similar name.

* @see <a href="https://redis.io/commands/set/">redis.io</a>
*/
@Builder
public final class SetOptions {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be updated from changes in #894.

Copy link
Contributor

@shachlanAmazon shachlanAmazon left a comment

Choose a reason for hiding this comment

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

approved, assuming the set/info specific code is removed.

* @see <a href="https://redis.io/commands/set/">redis.io</a>
*/
@Builder
public final class SetOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be remove from this PR?
You can add it after the set PR is merged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was actually intending to merge this after the set() command PR. There's no rush on this one.

* @see <a href="https://redis.io/commands/info/">redis.io</a>
*/
@Builder
public final class InfoOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be removed from this PR? you can add it after the info command PR is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was actually intending to merge this after the info() command PR. There's no rush on this one.

@acarbonetto acarbonetto force-pushed the java/integ_acarbo_api_transactions_only branch from b5fc521 to c98feb2 Compare February 11, 2024 09:27
clusterClient.exec(transaction, RANDOM).get(10, TimeUnit.SECONDS);
Object[] results =
Arrays.stream(clusterValues)
.map(v -> v.hasSingleData() ? v.getSingleValue() : v.getMultiValue())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be always multivalue for cluster isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

depends on the route

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I missed this - transactions only support routing to single nodes, so there's no need to use ClusterValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will submit a follow-up PR to fix this then. Thanks for the comment.

acarbonetto and others added 14 commits February 12, 2024 11:51
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Andrew Carbonetto <[email protected]>
@acarbonetto acarbonetto force-pushed the java/integ_acarbo_api_transactions_only branch from 8dc38f6 to e25c55f Compare February 12, 2024 20:08
@acarbonetto acarbonetto merged commit 8823a1a into valkey-io:main Feb 12, 2024
11 checks passed
@Yury-Fridlyand Yury-Fridlyand deleted the java/integ_acarbo_api_transactions_only branch February 12, 2024 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java issues and fixes related to the java client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants