From b140b50cca69953229720c77c206ba672a3918d3 Mon Sep 17 00:00:00 2001 From: Guian Gumpac Date: Mon, 22 Jul 2024 12:13:40 -0700 Subject: [PATCH] Updated docs Signed-off-by: Guian Gumpac --- node/src/BaseClient.ts | 11 +++-------- node/src/Commands.ts | 3 +++ node/src/Transaction.ts | 10 +--------- node/tests/SharedTests.ts | 26 +++++++++----------------- 4 files changed, 16 insertions(+), 34 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index b46881826b..e6b93cd5d5 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1759,21 +1759,20 @@ export class BaseClient { * @param key - The key of the sorted set. * @param membersScoresMap - A mapping of members to their corresponding scores. * @param options - The ZAdd options. - * @param changed - Modify the return value from the number of new elements added, to the total number of elements changed. * @returns The number of elements added to the sorted set. * If `changed` is set, returns the number of elements updated in the sorted set. * * @example * ```typescript * // Example usage of the zadd method to add elements to a sorted set - * const result = await client.zadd("my_sorted_set", \{ "member1": 10.5, "member2": 8.2 \}); + * const result = await client.zadd("my_sorted_set", { "member1": 10.5, "member2": 8.2 }); * console.log(result); // Output: 2 - Indicates that two elements have been added to the sorted set "my_sorted_set." * ``` * * @example * ```typescript * // Example usage of the zadd method to update scores in an existing sorted set - * const result = await client.zadd("existing_sorted_set", { member1: 15.0, member2: 5.5 }, options={ conditionalChange: "onlyIfExists" } , changed=true); + * const result = await client.zadd("existing_sorted_set", { member1: 15.0, member2: 5.5 }, { conditionalChange: "onlyIfExists", changed: true }); * console.log(result); // Output: 2 - Updates the scores of two existing members in the sorted set "existing_sorted_set." * ``` */ @@ -1783,11 +1782,7 @@ export class BaseClient { options?: ZAddOptions, ): Promise { return this.createWritePromise( - createZAdd( - key, - membersScoresMap, - options, - ), + createZAdd(key, membersScoresMap, options), ); } diff --git a/node/src/Commands.ts b/node/src/Commands.ts index a3c986993d..5b858dbe4e 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -843,6 +843,9 @@ export type ZAddOptions = { * is greater than the current score. Equivalent to `GT` in the Redis API. */ updateOptions?: "scoreLessThanCurrent" | "scoreGreaterThanCurrent"; + /** + * Modify the return value from the number of new elements added, to the total number of elements changed. + */ changed?: boolean; }; diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 66b5df47e6..67ffc8cc20 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -971,7 +971,6 @@ export class BaseTransaction> { * @param key - The key of the sorted set. * @param membersScoresMap - A mapping of members to their corresponding scores. * @param options - The ZAdd options. - * @param changed - Modify the return value from the number of new elements added, to the total number of elements changed. * * Command Response - The number of elements added to the sorted set. * If `changed` is set, returns the number of elements updated in the sorted set. @@ -981,13 +980,7 @@ export class BaseTransaction> { membersScoresMap: Record, options?: ZAddOptions, ): T { - return this.addAndReturn( - createZAdd( - key, - membersScoresMap, - options, - ), - ); + return this.addAndReturn(createZAdd(key, membersScoresMap, options)); } /** Increments the score of member in the sorted set stored at `key` by `increment`. @@ -1009,7 +1002,6 @@ export class BaseTransaction> { increment: number, options?: ZAddOptions, ): T { - return this.addAndReturn( createZAdd(key, { [member]: increment }, options, true), ); diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 0236d8e444..23a0ab8e18 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -1780,7 +1780,7 @@ export function runBaseTests(config: { await runTest(async (client: BaseClient) => { const key = uuidv4(); const membersScores = { one: 1, two: 2, three: 3 }; - const newMembersScores = { one: 2, two: 3}; + const newMembersScores = { one: 2, two: 3 }; expect(await client.zadd(key, membersScores)).toEqual(3); expect(await client.zaddIncr(key, "one", 2)).toEqual(3.0); @@ -1837,25 +1837,17 @@ export function runBaseTests(config: { membersScores["one"] = 10; expect( - await client.zadd( - key, - membersScores, - { - updateOptions: "scoreGreaterThanCurrent", - changed: true, - }, - ), + await client.zadd(key, membersScores, { + updateOptions: "scoreGreaterThanCurrent", + changed: true, + }), ).toEqual(1); expect( - await client.zadd( - key, - membersScores, - { - updateOptions: "scoreLessThanCurrent", - changed: true, - }, - ), + await client.zadd(key, membersScores, { + updateOptions: "scoreLessThanCurrent", + changed: true, + }), ).toEqual(0); expect(