Skip to content

Commit

Permalink
[Redis 6.2] Add ZMSCORE command
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Oct 7, 2021
1 parent eb626f6 commit 941e413
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,23 @@ def zscore(key, member)
end
end

# Get the scores associated with the given members in a sorted set.
#
# @example Get the scores for members "a" and "b"
# redis.zmscore("zset", "a", "b")
# # => [32.0, 48.0]
#
# @param [String] key
# @param [String, Array<String>] members
# @return [Array<Float>] scores of the members
def zmscore(key, *members)
synchronize do |client|
client.call([:zmscore, key, *members]) do |reply|
reply.map(&Floatify)
end
end
end

# Return a range of members in a sorted set, by index.
#
# @example Retrieve all members from a sorted set
Expand Down
5 changes: 5 additions & 0 deletions lib/redis/distributed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,11 @@ def zscore(key, member)
node_for(key).zscore(key, member)
end

# Get the scores associated with the given members in a sorted set.
def zmscore(key, *members)
node_for(key).zmscore(key, *members)
end

# Return a range of members in a sorted set, by index.
def zrange(key, start, stop, **options)
node_for(key).zrange(key, start, stop, **options)
Expand Down
12 changes: 12 additions & 0 deletions test/lint/sorted_sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ def test_zscore
assert_equal(+Float::INFINITY, r.zscore("bar", "s2"))
end

def test_zmscore
r.zadd "foo", 1, "s1"

assert_equal [1.0], r.zmscore("foo", "s1")
assert_equal [nil], r.zmscore("foo", "s2")

r.zadd "foo", "-inf", "s2"
r.zadd "foo", "+inf", "s3"
assert_equal [1.0, nil], r.zmscore("foo", "s1", "s4")
assert_equal [-Float::INFINITY, +Float::INFINITY], r.zmscore("foo", "s2", "s3")
end

def test_zremrangebyrank
r.zadd "foo", 10, "s1"
r.zadd "foo", 20, "s2"
Expand Down

0 comments on commit 941e413

Please sign in to comment.