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
5b73b9f to
97041b8
Compare
b09199f to
384af07
Compare
|
@Yury-Fridlyand |
|
LGTM, I applied minor doc updates. Need a second approval. |
| * String value = client.set("key", "value", options).get(); | ||
| * assert value.equals("OK"); | ||
| * }</pre> | ||
| * <pre>{@code |
There was a problem hiding this comment.
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
| * 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 |
| * API. | ||
| */ | ||
| ONLY_IF_DOES_NOT_EXIST("NX"); | ||
| ONLY_IF_DOES_NOT_EXIST("NX"), |
There was a problem hiding this comment.
Here a confusion starts - are these mutual exclusive? You should doc it
There was a problem hiding this comment.
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 failIn this approach, the last condition set will be the one that applies.
@ikolomi what do you think?
There was a problem hiding this comment.
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.
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.
``
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 <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>
Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
9cecbad to
05cd90a
Compare
Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
| * @param value The value to compare. | ||
| * @return This builder instance. | ||
| */ | ||
| public SetOptionsBuilder conditionalSetIfEqualTo(@NonNull String value) { |
There was a problem hiding this comment.
``
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
* start ifeq in java Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * set option + two tests Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * add docstring, throw errors, changelog Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * add conditionalSetIfEqualTo builder Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * add conditionalSet builder for OXX and NX and change comparisonValue to NonNull Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * Enforce mutual exclusive + yuri fixes * mutual exclusive Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * docstring and lint Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> --------- Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
* start ifeq in java Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * set option + two tests Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * add docstring, throw errors, changelog Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * add conditionalSetIfEqualTo builder Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * add conditionalSet builder for OXX and NX and change comparisonValue to NonNull Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * Enforce mutual exclusive + yuri fixes * mutual exclusive Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> * docstring and lint Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il> --------- Signed-off-by: Maayan Shani <maayan.shani@mail.huji.ac.il>
Issue link
This Pull Request is linked to issue (URL): [/issues/2811]
Description
This pull Request is implemented the
IFEQoption in theSETcommamnd. Tests were added, and docstring to the command and the related method.Checklist
Before submitting the PR make sure the following are checked: