Method: Redis::Commands::SortedSets#zunion

Defined in:
lib/redis/commands/sorted_sets.rb

#zunion(*args) ⇒ Array<String>, Array<[String, Float]>

Return the union of multiple sorted sets

Examples:

Retrieve the union of ‘2*zsetA` and `1*zsetB`

redis.zunion("zsetA", "zsetB", :weights => [2.0, 1.0])
  # => ["v1", "v2"]

Retrieve the union of ‘2*zsetA` and `1*zsetB`, and their scores

redis.zunion("zsetA", "zsetB", :weights => [2.0, 1.0], :with_scores => true)
  # => [["v1", 3.0], ["v2", 6.0]]

Parameters:

  • keys (String, Array<String>)

    one or more keys to union

  • options (Hash)
    • ‘:weights => [Array<Float>]`: weights to associate with source

    sorted sets

    • ‘:aggregate => String`: aggregate function to use (sum, min, max)

    • ‘:with_scores => true`: include scores in output

Returns:

  • (Array<String>, Array<[String, Float]>)
    • when ‘:with_scores` is not specified, an array of members

    • when ‘:with_scores` is specified, an array with `[member, score]` pairs



678
679
680
# File 'lib/redis/commands/sorted_sets.rb', line 678

def zunion(*args)
  _zsets_operation(:zunion, *args)
end