@@ -224,6 +224,38 @@ trait SortedSetsApi extends ApiSubset {
224224 def zscore (key : Key , member : Value ): Result [Opt [Double ]] =
225225 execute(new Zscore (key, member))
226226
227+ /** Executes [[http://redis.io/commands/zunion ZUNION ]] */
228+ def zunion (key : Key , keys : Key * ): Result [Seq [Value ]] =
229+ zunion(key +:: keys)
230+
231+ /** Executes [[http://redis.io/commands/zunion ZUNION ]] */
232+ def zunion (keys : Iterable [Key ], aggregation : OptArg [Aggregation ] = OptArg .Empty ): Result [Seq [Value ]] =
233+ execute(new Zunion (keys, Opt .Empty , aggregation.toOpt))
234+
235+ /** Executes [[http://redis.io/commands/zunion ZUNION ]] */
236+ def zunionWeights (keyWeight : (Key , Double ), keysWeights : (Key , Double )* ): Result [Seq [Value ]] =
237+ zunionWeights(keyWeight +:: keysWeights)
238+
239+ /** Executes [[http://redis.io/commands/zunion ZUNION ]] */
240+ def zunionWeights (keysWeights : Iterable [(Key , Double )], aggregation : OptArg [Aggregation ] = OptArg .Empty ): Result [Seq [Value ]] =
241+ execute(new Zunion (keysWeights.map(_._1), keysWeights.map(_._2).opt, aggregation.toOpt))
242+
243+ /** Executes [[http://redis.io/commands/zunion ZUNION ]] */
244+ def zunionWithscores (key : Key , keys : Key * ): Result [Seq [(Value , Double )]] =
245+ zunionWithscores(key +:: keys)
246+
247+ /** Executes [[http://redis.io/commands/zunion ZUNION ]] */
248+ def zunionWithscores (keys : Iterable [Key ], aggregation : OptArg [Aggregation ] = OptArg .Empty ): Result [Seq [(Value , Double )]] =
249+ execute(new ZunionWithscores (keys, Opt .Empty , aggregation.toOpt))
250+
251+ /** Executes [[http://redis.io/commands/zunion ZUNION ]] */
252+ def zunionWeightsWithscores (keyWeight : (Key , Double ), keysWeights : (Key , Double )* ): Result [Seq [(Value , Double )]] =
253+ zunionWeightsWithscores(keyWeight +:: keysWeights)
254+
255+ /** Executes [[http://redis.io/commands/zunion ZUNION ]] */
256+ def zunionWeightsWithscores (keysWeights : Iterable [(Key , Double )], aggregation : OptArg [Aggregation ] = OptArg .Empty ): Result [Seq [(Value , Double )]] =
257+ execute(new ZunionWithscores (keysWeights.map(_._1), keysWeights.map(_._2).opt, aggregation.toOpt))
258+
227259 /** Executes [[http://redis.io/commands/zunionstore ZUNIONSTORE ]] */
228260 def zunionstore (destination : Key , key : Key , keys : Key * ): Result [Long ] = zunionstore(destination, key +:: keys)
229261
@@ -257,6 +289,9 @@ trait SortedSetsApi extends ApiSubset {
257289 def bzpopmin (keys : Iterable [Key ], timeout : Int ): Result [Opt [(Key , Value , Double )]] =
258290 execute(new Bzpopmin (keys, timeout))
259291
292+ private abstract class AbstractValuesWithScoresCommand
293+ extends AbstractRedisCommand [Seq [(Value , Double )]](flatMultiBulkAsPairSeq(bulkAs[Value ], bulkAsDouble))
294+
260295 private abstract class AbstractZadd [T ](decoder : ReplyDecoder [T ])
261296 (key : Key , memberScores : IterableOnce [(Value , Double )], existence : Opt [Existence ], changed : Boolean , incr : Boolean )
262297 extends AbstractRedisCommand [T ](decoder) with NodeCommand {
@@ -289,8 +324,7 @@ trait SortedSetsApi extends ApiSubset {
289324 val encoded : Encoded = encoder(" ZDIFFSTORE" ).key(destination).add(keys.size).keys(keys).result
290325 }
291326
292- private final class ZdiffWithscores (keys : Iterable [Key ])
293- extends AbstractRedisCommand [Seq [(Value , Double )]](flatMultiBulkAsPairSeq(bulkAs[Value ], bulkAsDouble)) with NodeCommand {
327+ private final class ZdiffWithscores (keys : Iterable [Key ]) extends AbstractValuesWithScoresCommand with NodeCommand {
294328 val encoded : Encoded = encoder(" ZDIFF" ).add(keys.size).keys(keys).add(" WITHSCORES" ).result
295329 }
296330
@@ -311,7 +345,7 @@ trait SortedSetsApi extends ApiSubset {
311345 }
312346
313347 private final class ZinterWithscores (keys : Iterable [Key ], weights : Opt [Iterable [Double ]], aggregation : Opt [Aggregation ])
314- extends AbstractRedisCommand [ Seq [( Value , Double )]](flatMultiBulkAsPairSeq(bulkAs[ Value ], bulkAsDouble)) with NodeCommand {
348+ extends AbstractValuesWithScoresCommand with NodeCommand {
315349 val encoded : Encoded = encoder(" ZINTER" ).add(keys.size).keys(keys)
316350 .optAdd(" WEIGHTS" , weights).optAdd(" AGGREGATE" , aggregation).add(" WITHSCORES" ).result
317351 }
@@ -328,12 +362,12 @@ trait SortedSetsApi extends ApiSubset {
328362 }
329363
330364 private final class Zpopmin (key : Key , count : Opt [Long ])
331- extends AbstractRedisCommand [ Seq [( Value , Double )]](flatMultiBulkAsPairSeq(bulkAs[ Value ], bulkAsDouble)) with NodeCommand {
365+ extends AbstractValuesWithScoresCommand with NodeCommand {
332366 val encoded : Encoded = encoder(" ZPOPMIN" ).key(key).optAdd(count).result
333367 }
334368
335369 private final class Zpopmax (key : Key , count : Opt [Long ])
336- extends AbstractRedisCommand [ Seq [( Value , Double )]](flatMultiBulkAsPairSeq(bulkAs[ Value ], bulkAsDouble)) with NodeCommand {
370+ extends AbstractValuesWithScoresCommand with NodeCommand {
337371 val encoded : Encoded = encoder(" ZPOPMAX" ).key(key).optAdd(count).result
338372 }
339373
@@ -420,12 +454,24 @@ trait SortedSetsApi extends ApiSubset {
420454 val encoded : Encoded = encoder(" ZSCORE" ).key(key).data(member).result
421455 }
422456
457+ private final class Zunion (keys : Iterable [Key ], weights : Opt [Iterable [Double ]], aggregation : Opt [Aggregation ])
458+ extends RedisDataSeqCommand [Value ] with NodeCommand {
459+ val encoded : Encoded = encoder(" ZUNION" ).add(keys.size).keys(keys)
460+ .optAdd(" WEIGHTS" , weights).optAdd(" AGGREGATE" , aggregation).result
461+ }
462+
423463 private final class Zunionstore (destination : Key , keys : Iterable [Key ], weights : Opt [Iterable [Double ]], aggregation : Opt [Aggregation ])
424464 extends RedisLongCommand with NodeCommand {
425465 val encoded : Encoded = encoder(" ZUNIONSTORE" ).key(destination).add(keys.size).keys(keys)
426466 .optAdd(" WEIGHTS" , weights).optAdd(" AGGREGATE" , aggregation).result
427467 }
428468
469+ private final class ZunionWithscores (keys : Iterable [Key ], weights : Opt [Iterable [Double ]], aggregation : Opt [Aggregation ])
470+ extends AbstractValuesWithScoresCommand with NodeCommand {
471+ val encoded : Encoded = encoder(" ZUNION" ).add(keys.size).keys(keys)
472+ .optAdd(" WEIGHTS" , weights).optAdd(" AGGREGATE" , aggregation).add(" WITHSCORES" ).result
473+ }
474+
429475 private final class Bzpopmax (keys : Iterable [Key ], timeout : Int )
430476 extends AbstractRedisCommand [Opt [(Key , Value , Double )]](multiBulkAsZTripleOf[Key , Value ]) with NodeCommand {
431477 val encoded : Encoded = encoder(" BZPOPMAX" ).keys(keys).add(timeout).result
0 commit comments