Skip to content

Commit cd56b19

Browse files
author
Roman Janusz
committed
redis: ZMSCORE
1 parent 96ba194 commit cd56b19

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

commons-redis/src/main/scala/com/avsystem/commons/redis/RedisCommand.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ abstract class RedisScanCommand[T](decoder: ReplyDecoder[Seq[T]])
189189
abstract class RedisSeqCommand[T](elementDecoder: ReplyDecoder[T])
190190
extends AbstractRedisCommand[Seq[T]](multiBulkAsSeq(elementDecoder))
191191

192+
abstract class RedisSeqOptCommand[T](elementDecoder: ReplyDecoder[T])
193+
extends AbstractRedisCommand[Seq[Opt[T]]](multiBulkAsSeq(nullBulkOr(elementDecoder)))
194+
192195
abstract class RedisOptSeqCommand[T](elementDecoder: ReplyDecoder[T])
193196
extends AbstractRedisCommand[Opt[Seq[T]]](nullMultiBulkOr(multiBulkAsSeq(elementDecoder)))
194197

commons-redis/src/main/scala/com/avsystem/commons/redis/commands/sortedSets.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ trait SortedSetsApi extends ApiSubset {
127127
def zlexcount(key: Key, min: LexLimit[Value] = LexLimit.MinusInf, max: LexLimit[Value] = LexLimit.PlusInf): Result[Long] =
128128
execute(new Zlexcount(key, min, max))
129129

130+
/** Executes [[http://redis.io/commands/zmscore ZMSCORE]] */
131+
def zmscore(key: Key, members: Value*): Result[Seq[Opt[Double]]] =
132+
execute(new Zmscore(key, members))
133+
134+
/** Executes [[http://redis.io/commands/zmscore ZMSCORE]] */
135+
def zmscore(key: Key, members: Iterable[Value]): Result[Seq[Opt[Double]]] =
136+
execute(new Zmscore(key, members))
137+
130138
/** Executes [[http://redis.io/commands/zpopmax ZPOPMAX]] */
131139
def zpopmax(key: Key): Result[Opt[(Value, Double)]] =
132140
execute(new Zpopmax(key, Opt.Empty).map(_.headOpt))
@@ -366,6 +374,11 @@ trait SortedSetsApi extends ApiSubset {
366374
val encoded: Encoded = encoder("ZPOPMIN").key(key).optAdd(count).result
367375
}
368376

377+
private final class Zmscore(key: Key, members: Iterable[Value])
378+
extends RedisSeqOptCommand[Double](bulkAsDouble) with NodeCommand {
379+
val encoded: Encoded = encoder("ZMSCORE").key(key).datas(members).result
380+
}
381+
369382
private final class Zpopmax(key: Key, count: Opt[Long])
370383
extends AbstractValuesWithScoresCommand with NodeCommand {
371384
val encoded: Encoded = encoder("ZPOPMAX").key(key).optAdd(count).result

commons-redis/src/test/scala/com/avsystem/commons/redis/commands/SortedSetsApiSuite.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ trait SortedSetsApiSuite extends CommandsSuite {
115115
zlexcount("key", LexLimit.incl("a"), LexLimit.excl("c")).assertEquals(2)
116116
}
117117

118+
apiTest("ZMSCORE") {
119+
setup(zadd("key", "a" -> 1.0, "b" -> 2.0, "c" -> 3.0, "d" -> 4.0))
120+
zmscore("key", "a", "b", "e").assertEquals(Seq(Opt(1.0), Opt(2.0), Opt.Empty))
121+
}
122+
118123
apiTest("ZPOPMAX") {
119124
setup(zadd("key", "lol" -> 1.0, "fuu" -> 2.0, "bar" -> 3.0, "fag" -> 4.0))
120125
zpopmax("???").assertEquals(Opt.Empty)

0 commit comments

Comments
 (0)