Method: Redis#zunionstore

Defined in:
lib/redis.rb

#zunionstore(destination, keys, options = {}) ⇒ Fixnum

Add multiple sorted sets and store the resulting sorted set in a new key.

Examples:

Compute the union of 2*zsetA with 1*zsetB, summing their scores

redis.zunionstore("zsetC", ["zsetA", "zsetB"], :weights => [2.0, 1.0], :aggregate => "sum")
  # => 8

Parameters:

  • destination (String)

    destination key

  • keys (Array<String>)

    source keys

  • options (Hash) (defaults to: {})
    • :weights => [Float, Float, ...]: weights to associate with source sorted sets
    • :aggregate => String: aggregate function to use (sum, min, max, ...)

Returns:

  • (Fixnum)

    number of elements in the resulting sorted set



1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
# File 'lib/redis.rb', line 1186

def zunionstore(destination, keys, options = {})
  args = []

  weights = options[:weights]
  args.concat ["WEIGHTS", *weights] if weights

  aggregate = options[:aggregate]
  args.concat ["AGGREGATE", aggregate] if aggregate

  synchronize do
    @client.call [:zunionstore, destination, keys.size, *(keys + args)]
  end
end