ZINTERSTORE
Syntax
ZINTERSTORE destination key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE <SUM | MIN | MAX>] [WITHSCORES]
Module
sortedsetCategories
write slow sortedsetDescription
Computes the intersection of the sets in the keys, with weights, aggregate and scores. The result is stored in destination.
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 intersection. 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 intersection between 2 sorted sets:
db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
cardinality, err := vault.ZInterStore("destination", []string{"key1", "key2"}, db.ZInterStoreOptions{})
Store the intersection between 2 sorted sets with a sum of the weighted scores:
db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
cardinality, err := vault.ZInterStore(
"destination",
[]string{"key1", "key2"},
db.ZInterStoreOptions{Weights: []float64{2, 4}, Aggregate: "SUM", WithScores: true},
)
Store the intersection between 2 sorted sets:
> ZINTERSTORE destination key1 key2
Store the intersection between 2 sorted sets with a sum of the weighted scores:
> ZINTERSTORE destination key1 key2 WEIGHTS 2 4 AGGREGATE SUM WITHSCORES