Skip to main content

ZUNION

Syntax

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

Module

sortedset

Categories

read slow sortedset

Description

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. WITHSCORES option determines whether to return the result with scores included.

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

Find the union between 2 sorted sets:

vault, err := echovault.NewEchoVault()
if err != nil {
log.Fatal(err)
}
sortedSet, err := vault.ZUnion([]string{"key1", "key2"}, echovault.ZUnionOptions{})

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

vault, err := echovault.NewEchoVault()
if err != nil {
log.Fatal(err)
}
sortedSet, err := vault.ZUnion(
[]string{"key1", "key2"},
echovault.ZUnionOptions{Weights: []float64{2, 4}, Aggregate: "SUM", WithScores: true},
)