From 041a662311b59328470d4dd3db57064c3b444e0b Mon Sep 17 00:00:00 2001 From: Maayan Shani Date: Wed, 1 Jan 2025 16:42:52 +0000 Subject: [PATCH] change variable name comparisonValue + fix docstring Signed-off-by: Maayan Shani --- node/src/BaseClient.ts | 4 +- node/src/Commands.ts | 71 +++++++++++----------- node/tests/SharedTests.ts | 8 +-- python/python/glide/async_commands/core.py | 2 - 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 30d58a976f..2e0fbfc74c 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -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( diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 8d6952057d..c90c5bcacf 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -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. @@ -151,10 +152,10 @@ export interface SetOptions { * `KEEPTTL` in the Valkey API. */ | "keepExisting" - | { - type: TimeUnit; - count: number; - }; + | { + type: TimeUnit; + count: number; + }; } /** @@ -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'", ); } } @@ -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( @@ -1713,15 +1714,15 @@ export type Boundary = * 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. @@ -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 diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index bd78de8085..162eea4bf3 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -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"); @@ -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 @@ -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) { diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 880bf29642..85c361f7d3 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -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):