-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node: Add ZUNIONSTORE command #1550
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -77,17 +77,20 @@ import { | |||||
createSMove, | ||||||
createSPop, | ||||||
createSRem, | ||||||
createSUnionStore, | ||||||
createSet, | ||||||
createStrlen, | ||||||
createTTL, | ||||||
createType, | ||||||
createUnlink, | ||||||
createXAdd, | ||||||
createXLen, | ||||||
createXRead, | ||||||
createXTrim, | ||||||
createZAdd, | ||||||
createZCard, | ||||||
createZCount, | ||||||
createZInterCard, | ||||||
createZInterstore, | ||||||
createZPopMax, | ||||||
createZPopMin, | ||||||
|
@@ -98,9 +101,7 @@ import { | |||||
createZRemRangeByRank, | ||||||
createZRemRangeByScore, | ||||||
createZScore, | ||||||
createSUnionStore, | ||||||
createXLen, | ||||||
createZInterCard, | ||||||
createZUnionStore, | ||||||
} from "./Commands"; | ||||||
import { | ||||||
ClosingError, | ||||||
|
@@ -1973,6 +1974,43 @@ export class BaseClient { | |||||
); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Computes the union of sorted sets given by the specified `keys` and stores the result in `destination`. | ||||||
* If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created. | ||||||
* To get the result directly, see `zunion_withscores`. | ||||||
* | ||||||
* When in cluster mode, `destination` and all keys in `keys` must map to the same hash slot. | ||||||
* | ||||||
* See https://valkey.io/commands/zunionstore/ for more details. | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* @param destination - The key of the destination sorted set. | ||||||
* @param keys - The keys of the sorted sets with possible formats: | ||||||
* string[] - for keys only. | ||||||
* KeyWeight[] - for weighted keys with score multipliers. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does weighted is clear to the user? I don't know what its mean so i would like to have an explantation in the docs, but if it's normally known to the user it is not necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Java, we linked to the documentation for WeightedKeys object. Is it easy to jump to KeyWeight object on PyCharm? |
||||||
* @param aggregationType - Specifies the aggregation strategy to apply when combining the scores of elements. See `AggregationType`. | ||||||
* @returns The number of elements in the resulting sorted set stored at `destination`. | ||||||
* | ||||||
* @example | ||||||
* ```typescript | ||||||
* // Example usage of zunionStore command with an existing key | ||||||
* await client.zadd("key1", {"member1": 10.5, "member2": 8.2}) | ||||||
* await client.zadd("key2", {"member1": 9.5}) | ||||||
* await client.zunionStore("my_sorted_set", ["key1", "key2"]) // Output: 2 - Indicates that the sorted set "my_sorted_set" contains two elements. | ||||||
* await client.zrangeWithScores("my_sorted_set", RangeByIndex(0, -1)) // Output: {'member1': 20, 'member2': 8.2} - "member1" is now stored in "my_sorted_set" with score of 20 and "member2" with score of 8.2. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add an example of using weighted? |
||||||
* await client.zunionStore("my_sorted_set", ["key1", "key2"] , AggregationType.MAX ) // Output: 2 - Indicates that the sorted set "my_sorted_set" contains two elements, and each score is the maximum score between the sets. | ||||||
* await client.zrangeWithScores("my_sorted_set", RangeByIndex(0, -1)) // Output: {'member1': 10.5, 'member2': 8.2} - "member1" is now stored in "my_sorted_set" with score of 10.5 and "member2" with score of 8.2. | ||||||
* ``` | ||||||
*/ | ||||||
public zunionStore( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be in lowercase
Suggested change
Please update examples too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're not too consistent with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a single word command name, so in user API we do the same. |
||||||
destination: string, | ||||||
keys: string[] | KeyWeight[], | ||||||
aggregationType?: AggregationType, | ||||||
): Promise<number> { | ||||||
return this.createWritePromise( | ||||||
createZUnionStore(destination, keys, aggregationType), | ||||||
); | ||||||
} | ||||||
|
||||||
/** Returns the length of the string value stored at `key`. | ||||||
* See https://redis.io/commands/strlen/ for more details. | ||||||
* | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -80,6 +80,7 @@ import { | |||||
createSMove, | ||||||
createSPop, | ||||||
createSRem, | ||||||
createSUnionStore, | ||||||
createSelect, | ||||||
createSet, | ||||||
createStrlen, | ||||||
|
@@ -88,11 +89,13 @@ import { | |||||
createType, | ||||||
createUnlink, | ||||||
createXAdd, | ||||||
createXLen, | ||||||
createXRead, | ||||||
createXTrim, | ||||||
createZAdd, | ||||||
createZCard, | ||||||
createZCount, | ||||||
createZInterCard, | ||||||
createZInterstore, | ||||||
createZPopMax, | ||||||
createZPopMin, | ||||||
|
@@ -103,9 +106,7 @@ import { | |||||
createZRemRangeByRank, | ||||||
createZRemRangeByScore, | ||||||
createZScore, | ||||||
createSUnionStore, | ||||||
createXLen, | ||||||
createZInterCard, | ||||||
createZUnionStore, | ||||||
} from "./Commands"; | ||||||
import { redis_request } from "./ProtobufMessage"; | ||||||
|
||||||
|
@@ -1103,6 +1104,30 @@ export class BaseTransaction<T extends BaseTransaction<T>> { | |||||
); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Computes the union of sorted sets given by the specified `keys` and stores the result in `destination`. | ||||||
* If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created. | ||||||
* To get the result directly, see `zunion_withscores`. | ||||||
* | ||||||
* See https://valkey.io/commands/zunionstore/ for more details. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* @param destination - The key of the destination sorted set. | ||||||
* @param keys - The keys of the sorted sets with possible formats: | ||||||
* string[] - for keys only. | ||||||
* KeyWeight[] - for weighted keys with score multipliers. | ||||||
* @param aggregationType - Specifies the aggregation strategy to apply when combining the scores of elements. See `AggregationType`. | ||||||
* Command Response - The number of elements in the resulting sorted set stored at `destination`. | ||||||
*/ | ||||||
public zunionStore( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
destination: string, | ||||||
keys: string[] | KeyWeight[], | ||||||
aggregationType?: AggregationType, | ||||||
): T { | ||||||
return this.addAndReturn( | ||||||
createZUnionStore(destination, keys, aggregationType), | ||||||
); | ||||||
} | ||||||
|
||||||
/** Returns the string representation of the type of the value stored at `key`. | ||||||
* See https://redis.io/commands/type/ for more details. | ||||||
* | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.