diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 9f20d11ff7..d9479e8d93 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1496,8 +1496,11 @@ 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", comparisonValue: "new_value"); - * console.log(result5); // Output: 'OK' - Set "ifeq_value" to "key" only if comparisonValue is equal to the value of "key". + * await client.set("key", "value we will compare to"); + * const result5 = await client.set("key", "new_value", {conditionalSet: "onlyIfEqual", comparisonValue: "value we will compare to"}); + * console.log(result5); // Output: 'OK' - Set "new_value" to "key" only if comparisonValue is equal to the current value of "key". + * const result6 = await client.set("key", "another_new_value", {conditionalSet: "onlyIfEqual", comparisonValue: "value we will compare to"}); + * console.log(result6); // Output: `null` - Value wasn't set because the comparisonValue is not equal to the current value of "key". Value of "key" remains "new_value". * ``` */ public async set( diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 2901a2b483..97c36ce694 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -128,17 +128,17 @@ export type SetOptions = ( | { /** * `onlyIfDoesNotExist` - Only set the key if it does not already exist. - * Equivalent to `NX` in the Valkey API. + * `NX` in the Valkey API. * * `onlyIfExists` - Only set the key if it already exists. - * Equivalent to `EX` in the Valkey API. + * `EX` in the Valkey API. */ conditionalSet?: "onlyIfExists" | "onlyIfDoesNotExist"; } | { /** - * `onlyIfEqual` - Only set the key if the comparison value equals the key value. - * Equivalent to `IFEQ` in the Valkey API. + * `onlyIfEqual` - Only set the key if the comparison value equals the current value of key. + * `IFEQ` in the Valkey API. */ conditionalSet: "onlyIfEqual"; /** diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 2be41de1bd..ed6c9b4cb6 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -8284,6 +8284,22 @@ export function runBaseTests(config: { expect(setResWithAllOptions).toEqual(initialValue); // newValue should be set as the key value expect(await client.get(key)).toEqual(newValue); + + // fail command + const wrongValue = "wrong value"; + const setResFailedWithAllOptions = await client.set(key, wrongValue, { + expiry: { + type: TimeUnit.UnixSeconds, + count: Math.floor(Date.now() / 1000) + 1, + }, + conditionalSet: "onlyIfEqual", + comparisonValue: wrongValue, + returnOldValue: true, + }); + // current value of key should be newValue + expect(setResFailedWithAllOptions).toEqual(newValue); + // key should not be set. it remains the same + expect(await client.get(key)).toEqual(newValue); } async function testSetWithAllCombination(