-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
@Yury-Fridlyand |
Java is not so flexible, unfortunately. |
So for now I see two options.
What do you think is better? |
8894244
to
772e82f
Compare
java/client/src/main/java/glide/api/commands/StringBaseCommands.java
Outdated
Show resolved
Hide resolved
5b73b9f
to
97041b8
Compare
java/client/src/main/java/glide/api/commands/StringBaseCommands.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/commands/SetOptions.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/commands/SetOptions.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/commands/SetOptions.java
Outdated
Show resolved
Hide resolved
b09199f
to
384af07
Compare
@Yury-Fridlyand |
java/client/src/main/java/glide/api/models/commands/SetOptions.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/commands/SetOptions.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/commands/SetOptions.java
Outdated
Show resolved
Hide resolved
java/client/src/main/java/glide/api/models/commands/SetOptions.java
Outdated
Show resolved
Hide resolved
LGTM, I applied minor doc updates. Need a second approval. |
@@ -223,6 +223,12 @@ public interface StringBaseCommands { | |||
* String value = client.set("key", "value", options).get(); | |||
* assert value.equals("OK"); | |||
* }</pre> | |||
* <pre>{@code |
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.
Apparently addition of IFEQ out-dates the @return doc above.
Since it becomes complicated to explain all the implications introduced by the new options, perhaps the return doc string should only mention that the set options affect the return behavior. In case you prefer to keep the full explanation in the return doc, extend it with IFEQ
@@ -235,8 +241,9 @@ public interface StringBaseCommands { | |||
* @param options The Set options. | |||
* @return If the value is successfully set, return <code>"OK"</code>. If value isn't set because | |||
* of {@link ConditionalSet#ONLY_IF_EXISTS} or {@link ConditionalSet#ONLY_IF_DOES_NOT_EXIST} | |||
* conditions, return <code>null</code>. If {@link SetOptionsBuilder#returnOldValue(boolean)} | |||
* is set, return the old value as a <code>String</code>. | |||
* or {@link ConditionalSet#ONLY_IF_EQUAL} conditions, return <code>null</code>. If {@link |
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.
same as above
@@ -49,11 +53,52 @@ public enum ConditionalSet { | |||
* Only set the key if it does not already exist. Equivalent to <code>NX</code> in the Valkey | |||
* API. | |||
*/ | |||
ONLY_IF_DOES_NOT_EXIST("NX"); | |||
ONLY_IF_DOES_NOT_EXIST("NX"), |
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.
Here a confusion starts - are these mutual exclusive? You should doc it
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.
It's not possible for a key to both exist and not exist at the same time, so the user can specify only one condition. In the Valkey API, you can choose SET key value [NX | XX | IFEQ comparison-value]
.
There is no contradiction between the XX
and IFEQ comparison-value
conditions but in the API of valkey they chose to apply only one of them.
In Java, it's a bit complicated to enforce this. In Node.js, I created a new type to apply only one of the conditionals, but here it's a bit different. I think it's okay to use the format we did and as Yuri mentioned above:
SetOptions.builder().conditionalSetIfEqualTo("abc").conditionalSet(ONLY_IF_DOES_NOT_EXIST).build(); // should not fail
SetOptions.builder().conditionalSet(ONLY_IF_EQUAL).build(); // should fail
In this approach, the last condition set will be the one that applies.
@ikolomi what do you think?
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 think we need to enforce the mutual exclusiveness by throwing from the builder's setters
* @param value The value to compare. | ||
* @return This builder instance. | ||
*/ | ||
public SetOptionsBuilder conditionalSetIfEqualTo(@NonNull String value) { |
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 suspect we want these conditions to be mutual exclusive ? If so, we should enforce it by throwing
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.
``
public SetOptionsBuilder conditionalIfExistst() {
}
public SetOptionsBuilder conditionalIfNotExistst() {
}
public SetOptionsBuilder conditionalIfEqual(@nonnull String value) {
}
``
Lest the methods to override the current value + describe in the docs that the conditions are mutual exclusive
@Maayanshani25 please dont forget to squash |
1becf23
to
9cecbad
Compare
Signed-off-by: Maayan Shani <[email protected]>
Signed-off-by: Maayan Shani <[email protected]>
Signed-off-by: Maayan Shani <[email protected]>
Signed-off-by: Maayan Shani <[email protected]>
…to NonNull Signed-off-by: Maayan Shani <[email protected]>
Signed-off-by: Maayan Shani <[email protected]>
9cecbad
to
05cd90a
Compare
Signed-off-by: Maayan Shani <[email protected]>
* @param value The value to compare. | ||
* @return This builder instance. | ||
*/ | ||
public SetOptionsBuilder conditionalSetIfEqualTo(@NonNull String value) { |
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.
``
public SetOptionsBuilder conditionalIfExistst() {
}
public SetOptionsBuilder conditionalIfNotExistst() {
}
public SetOptionsBuilder conditionalIfEqual(@nonnull String value) {
}
``
Lest the methods to override the current value + describe in the docs that the conditions are mutual exclusive
Issue link
This Pull Request is linked to issue (URL): [/issues/2811]
Description
This pull Request is implemented the
IFEQ
option in theSET
commamnd. Tests were added, and docstring to the command and the related method.Checklist
Before submitting the PR make sure the following are checked: