Skip to content

Commit

Permalink
change variable name comparisonValue + fix docstring
Browse files Browse the repository at this point in the history
Signed-off-by: Maayan Shani <[email protected]>
  • Loading branch information
Maayanshani25 committed Jan 1, 2025
1 parent 5c9c138 commit febef71
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1495,8 +1495,8 @@ export class BaseClient {
* console.log(result4); // Output: 'new_value' - Value wasn't modified back to being "value" because of "NX" flag.
*
* // Example usage of set method with conditional option IFEQ
* const result5 = await client.set("key", "ifeq_value", {conditionalSet: "onlyIfEqual", providedValue: "new_value");
* console.log(result5); // Output: 'OK' - Set "ifeq_value" to "key" only if providedValue is equal to the value of "key".
* const result5 = await client.set("key", "ifeq_value", {conditionalSet: "onlyIfEqual", comparisonValue: "new_value");
* console.log(result5); // Output: 'OK' - Set "ifeq_value" to "key" only if comparisonValue is equal to the value of "key".
* ```
*/
public async set(
Expand Down
15 changes: 8 additions & 7 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ export interface SetOptions {
/**
* `onlyIfDoesNotExist` - Only set the key if it does not already exist.
* Equivalent to `NX` in the Valkey API. `onlyIfExists` - Only set the key if
* it already exist. Equivalent to `EX` in the Valkey API. if `conditional` is
* not set the value will be set regardless of prior value existence. If value
* isn't set because of the condition, return null.
* it already exist. Equivalent to `EX` in the Valkey API. `onlyIfEqual` - Only set the
* key if the comparison value equals to the key value. Equivalent to `IFEQ` in the Valkey API.
* if `conditional` is not set the value will be set regardless of prior value existence.
* If value isn't set because of the condition, return null.
*/
conditionalSet?: "onlyIfExists" | "onlyIfDoesNotExist" | "onlyIfEqual";
/**
* If onlyIfEqual is set, the value to compare the existing value with.
*/
providedValue?: GlideString;
comparisonValue?: GlideString;
/**
* Return the old string stored at key, or nil if key did not exist. An error
* is returned and SET aborted if the value stored at key is not a string.
Expand Down Expand Up @@ -175,11 +176,11 @@ export function createSet(
} else if (options.conditionalSet === "onlyIfEqual") {
args.push("IFEQ");

if (options.providedValue != undefined) {
args.push(options.providedValue);
if (options.comparisonValue != undefined) {
args.push(options.comparisonValue);
} else {
throw new Error(
"The 'providedValue' option must be set when using 'onlyIfEqual'",
"The 'comparisonValue' option must be set when using 'onlyIfEqual'",
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8147,14 +8147,14 @@ export function runBaseTests(config: {
// Attempt to set with a non-matching value (should fail -> return null)
const conditionalSetFailResponse = await client.set(key, newValue, {
conditionalSet: "onlyIfEqual",
providedValue: newValue,
comparisonValue: newValue,
});
expect(conditionalSetFailResponse).toEqual(null);

// Attempt to set with a matching value (should succeed -> return OK)
const conditionalSetSuccessResponse = await client.set(key, newValue, {
conditionalSet: "onlyIfEqual",
providedValue: initialValue,
comparisonValue: initialValue,
});
expect(conditionalSetSuccessResponse).toEqual("OK");

Expand Down Expand Up @@ -8246,7 +8246,7 @@ export function runBaseTests(config: {
count: Math.floor(Date.now() / 1000) + 1,
},
conditionalSet: "onlyIfEqual",
providedValue: initialValue,
comparisonValue: initialValue,
returnOldValue: true,
});
// initialValue should be get from the key
Expand Down Expand Up @@ -8338,7 +8338,7 @@ export function runBaseTests(config: {
count: number;
},
conditionalSet: "onlyIfEqual",
providedValue: value, // Ensure it matches the current key's value
comparisonValue: value, // Ensure it matches the current key's value
});

if (setRes) {
Expand Down
2 changes: 0 additions & 2 deletions python/python/glide/async_commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ class ConditionalChange(Enum):
A condition to the `SET`, `ZADD` and `GEOADD` commands.
- ONLY_IF_EXISTS - Only update key / elements that already exist. Equivalent to `XX` in the Valkey API.
- ONLY_IF_DOES_NOT_EXIST - Only set key / add elements that does not already exist. Equivalent to `NX` in the Valkey API.
- ONLY_IF_EQUAL - Only update key if the provided value is equal to the old value. Equivalent to `IFEQ` in the Valkey API.
"""

ONLY_IF_EXISTS = "XX"
ONLY_IF_DOES_NOT_EXIST = "NX"
ONLY_IF_EQUAL = "IFEQ"


class ExpiryType(Enum):
Expand Down

0 comments on commit febef71

Please sign in to comment.