ZUNIONSTORE
Syntax
ZUNIONSTORE destination key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE <SUM | MIN | MAX>] [WITHSCORES]
Module
sortedsetCategories
write slow sortedsetDescription
Return the union of the sorted sets in keys. The scores of each member of a sorted set are multiplied by the corresponding weight in WEIGHTS. Aggregate determines how the scores are combined. The resulting union is stored at the destination key.
Options
WEIGHTS
- A list of floats that determine the weight of each sorted set. The scores of each member of a sort set are multiplied by the corresponding weight. If weights are not provided, the default weight is 1 for all sorted sets.AGGREGATE
- Determines the strategy used to compare the scores of members in the union. SUM will add the scores, MIN will choose the minimum score, and MAX will choose the maximum score.WITHSCORES
- Determines whether scores should be included in the resulting sorted set.
Examples
- Go (Embedded)
- CLI
Store the union between 2 sorted sets:
db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
cardinality, err := vault.ZUnionStore("destination", []string{"key1", "key2"}, db.ZUnionStoreOptions{})
Store the union between 2 sorted sets with a sum of the weighted scores:
db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
cardinality, err := vault.ZUnionStore(
"destination",
[]string{"key1", "key2"},
db.ZUnionStoreOptions{Weights: []float64{2, 4}, Aggregate: "SUM", WithScores: true},
)
Store the union between 2 sorted sets:
> ZUNIONSTORE destination key1 key2
Store the union between 2 sorted sets with a sum of the weighted scores:
> ZUNIONSTORE destination key1 key2 WEIGHTS 2 4 AGGREGATE SUM WITHSCORES