Skip to content

Commit

Permalink
Merge pull request #1031 from fatkodima/smismember
Browse files Browse the repository at this point in the history
[Redis 6.2] Add SMISMEMBER command
  • Loading branch information
byroot authored Oct 7, 2021
2 parents d362283 + ead71c0 commit eb626f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,19 @@ def sismember(key, member)
end
end

# Determine if multiple values are members of a set.
#
# @param [String] key
# @param [String, Array<String>] members
# @return [Array<Boolean>]
def smismember(key, *members)
synchronize do |client|
client.call([:smismember, key, *members]) do |reply|
reply.map(&Boolify)
end
end
end

# Get all the members in a set.
#
# @param [String] key
Expand Down
5 changes: 5 additions & 0 deletions lib/redis/distributed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ def sismember(key, member)
node_for(key).sismember(key, member)
end

# Determine if multiple values are members of a set.
def smismember(key, *members)
node_for(key).smismember(key, *members)
end

# Get all the members in a set.
def smembers(key)
node_for(key).smembers(key)
Expand Down
12 changes: 12 additions & 0 deletions test/lint/sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ def test_sismember
assert_equal false, r.sismember("foo", "s2")
end

def test_smismember
target_version("6.2") do
assert_equal [false], r.smismember("foo", "s1")

r.sadd "foo", "s1"
assert_equal [true], r.smismember("foo", "s1")

r.sadd "foo", "s3"
assert_equal [true, false, true], r.smismember("foo", "s1", "s2", "s3")
end
end

def test_smembers
assert_equal [], r.smembers("foo")

Expand Down

0 comments on commit eb626f6

Please sign in to comment.