Skip to content

Commit

Permalink
add docstring, throw errors, changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Maayan Shani <[email protected]>
  • Loading branch information
Maayanshani25 committed Jan 22, 2025
1 parent 5e02d00 commit 7bce335
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Java: Shadow `protobuf` dependency ([#2931](https://github.com/valkey-io/valkey-glide/pull/2931))
* Java: Add `RESP2` support ([#2383](https://github.com/valkey-io/valkey-glide/pull/2383))
* Node, Python: Add `IFEQ` option ([#2909](https://github.com/valkey-io/valkey-glide/pull/2909), [#2962](https://github.com/valkey-io/valkey-glide/pull/2962))
* Java : Add `IFEQ` option ([#2978](https://github.com/valkey-io/valkey-glide/pull/2978))

#### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,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();
* String value = client.set("key", "newValue", options).get();
* assert value.equals("OK");
* }</pre>
*/
CompletableFuture<String> set(String key, String value, SetOptions options);

Expand All @@ -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
* SetOptionsBuilder#returnOldValue(boolean)} is set, return the old value as a <code>String
* </code>.
* @example
* <pre>{@code
* SetOptions options = SetOptions.builder().conditionalSet(ONLY_IF_EXISTS).expiry(Seconds(5L)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class SetOptions {
*/
private final ConditionalSet conditionalSet;

/** Value to compare when <code>IFEQ comparison-value</code> is set. */
/** Value to compare when {@link ConditionalSet#ONLY_IF_EQUAL} is set. */
private final String comparisonValue;

/**
Expand All @@ -54,8 +54,8 @@ public enum ConditionalSet {
*/
ONLY_IF_DOES_NOT_EXIST("NX"),
/**
* Only set the key if the current value equals the provided comparison value. Equivalent to
* <code>IFEQ comparison-value</code> in the Valkey API.
* Only set the key if the current value of key equals the {@link SetOptions#comparisonValue}.
* Equivalent to <code>IFEQ comparison-value</code> in the Valkey API.
*/
ONLY_IF_EQUAL("IFEQ");

Expand Down Expand Up @@ -163,8 +163,14 @@ public String[] toArgs() {

// Add comparison value if ONLY_IF_EQUAL is selected
if (conditionalSet == ConditionalSet.ONLY_IF_EQUAL) {
assert comparisonValue != null : "comparisonValue must be set for ONLY_IF_EQUAL condition.";
if (comparisonValue == null) {
throw new IllegalArgumentException(
"comparisonValue must be set when conditionalSet is ONLY_IF_EQUAL.");
}
optionArgs.add(comparisonValue);
} else if (comparisonValue != null) {
throw new IllegalArgumentException(
"comparisonValue can only be set when conditionalSet is ONLY_IF_EQUAL.");
}

if (returnOldValue) {
Expand Down

0 comments on commit 7bce335

Please sign in to comment.