Skip to main content

ZINTER

Syntax

ZINTER key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE <SUM | MIN | MAX>] [WITHSCORES]

Module

sortedset

Categories

read slow sortedset

Description

Computes the intersection of the sets in the keys, with weights, aggregate and scores.

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

Find the intersection between 2 sorted sets:

db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
sortedSet, err := db.ZInter([]string{"key1", "key2"}, db.ZInterOptions{})

Find the intersection between 2 sorted sets with a sum of the weighted scores:

db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
sortedSet, err := db.ZInter(
[]string{"key1", "key2"},
db.ZInterOptions{Weights: []float64{2, 4}, Aggregate: "SUM", WithScores: true},
)