Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
Signed-off-by: Guian Gumpac <[email protected]>
  • Loading branch information
GumpacG committed Jul 22, 2024
1 parent a9ab5b0 commit b140b50
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
11 changes: 3 additions & 8 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."
* ```
*/
Expand All @@ -1783,11 +1782,7 @@ export class BaseClient {
options?: ZAddOptions,
): Promise<number> {
return this.createWritePromise(
createZAdd(
key,
membersScoresMap,
options,
),
createZAdd(key, membersScoresMap, options),
);
}

Expand Down
3 changes: 3 additions & 0 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
10 changes: 1 addition & 9 deletions node/src/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,6 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
* @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.
Expand All @@ -981,13 +980,7 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
membersScoresMap: Record<string, number>,
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`.
Expand All @@ -1009,7 +1002,6 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
increment: number,
options?: ZAddOptions,
): T {

return this.addAndReturn(
createZAdd(key, { [member]: increment }, options, true),
);
Expand Down
26 changes: 9 additions & 17 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,7 @@ export function runBaseTests<Context>(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);
Expand Down Expand Up @@ -1837,25 +1837,17 @@ export function runBaseTests<Context>(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(
Expand Down

0 comments on commit b140b50

Please sign in to comment.