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

SET IFEQ command implemented in Java + tests #2978

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Maayanshani25
Copy link
Collaborator

@Maayanshani25 Maayanshani25 commented Jan 19, 2025

Issue link

This Pull Request is linked to issue (URL): [/issues/2811]

Description

This pull Request is implemented the IFEQ option in the SET commamnd. Tests were added, and docstring to the command and the related method.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

@Maayanshani25 Maayanshani25 requested a review from a team as a code owner January 19, 2025 10:28
@Maayanshani25
Copy link
Collaborator Author

@Yury-Fridlyand
I found the implementation of java a bit different than node.
Do you think it's possible to this the also here? #2909 (comment)

@Yury-Fridlyand Yury-Fridlyand added the java issues and fixes related to the java client label Jan 20, 2025
@Yury-Fridlyand
Copy link
Collaborator

Yury-Fridlyand commented Jan 20, 2025

Java is not so flexible, unfortunately.
But it is still possible to do if you customize the setter in the SetOptions builder. Probably, you can keep exposed ConditionalSet with 2 options, but under the hood have another one with 3 options.
Need to be careful to avoid breaking changes while doing refactoring.
StandaloneSubscriptionConfigurationBuilder is a nice example of a customized builder.

@Maayanshani25
Copy link
Collaborator Author

Maayanshani25 commented Jan 22, 2025

So for now I see two options.

  1. The implementation I did in the pr for now. If the user chooses the conditionalSet ONLY_IF_EQUAL, it makes sure comparisonValue isnt null and push them both to the args.
    If comparisonValue is set but The condionalSet is not ONLY_IF_EQUAL, throws an error

  2. Removing ONLY_IF_EQUAL from conditionalSet options and use it this way:

if (conditionalSet != null) {
            optionArgs.add(conditionalSet.valkeyApi);
} else if (comparisonValue != null) {
            optionArgs.add("IFEQ", comparisonValue);

}

What do you think is better?

@@ -223,6 +224,12 @@ public interface StringBaseCommands {
* String value = client.set("key", "value", options).get();
* assert value.equals("OK");
* }</pre>
* <pre>{@code
* client.set("key", "value").get();
* SetOptions options = SetOptions.builder().conditionalSet(ONLY_IF_EQUAL).comparisonValue("value")).build();
Copy link
Collaborator

Choose a reason for hiding this comment

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

With customized builder you can do something like

Suggested change
* SetOptions options = SetOptions.builder().conditionalSet(ONLY_IF_EQUAL).comparisonValue("value")).build();
* SetOptions options = SetOptions.builder().conditionalSetIfEqualTo("value").build();

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Yury-Fridlyand, could you please approve it or provide feedback by Sunday? The exam period starts next week.

@Maayanshani25 Maayanshani25 force-pushed the ifeq-java branch 2 times, most recently from 5b73b9f to 97041b8 Compare January 23, 2025 19:45
Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
…to NonNull

Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
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.

2 participants