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 041a662
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 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
71 changes: 36 additions & 35 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 All @@ -151,10 +152,10 @@ export interface SetOptions {
* `KEEPTTL` in the Valkey API.
*/
| "keepExisting"
| {
type: TimeUnit;
count: number;
};
| {
type: TimeUnit;
count: number;
};
}

/**
Expand All @@ -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 Expand Up @@ -1450,7 +1451,7 @@ export function createZAdd(
if (options.conditionalChange) {
if (
options.conditionalChange ===
ConditionalChange.ONLY_IF_DOES_NOT_EXIST &&
ConditionalChange.ONLY_IF_DOES_NOT_EXIST &&
options.updateOptions
) {
throw new Error(
Expand Down Expand Up @@ -1713,15 +1714,15 @@ export type Boundary<T> =
* Represents a specific boundary.
*/
| {
/**
* The comparison value.
*/
value: T;
/**
* Whether the value is inclusive. Defaults to `true`.
*/
isInclusive?: boolean;
};
/**
* The comparison value.
*/
value: T;
/**
* Whether the value is inclusive. Defaults to `true`.
*/
isInclusive?: boolean;
};

/**
* Represents a range by index (rank) in a sorted set.
Expand Down Expand Up @@ -2088,21 +2089,21 @@ export function createZRank(

export type StreamTrimOptions = (
| {
/**
* Trim the stream according to entry ID.
* Equivalent to `MINID` in the Valkey API.
*/
method: "minid";
threshold: GlideString;
}
/**
* Trim the stream according to entry ID.
* Equivalent to `MINID` in the Valkey API.
*/
method: "minid";
threshold: GlideString;
}
| {
/**
* Trim the stream according to length.
* Equivalent to `MAXLEN` in the Valkey API.
*/
method: "maxlen";
threshold: number;
}
/**
* Trim the stream according to length.
* Equivalent to `MAXLEN` in the Valkey API.
*/
method: "maxlen";
threshold: number;
}
) & {
/**
* If `true`, the stream will be trimmed exactly. Equivalent to `=` in the
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 041a662

Please sign in to comment.