Skip to content

Commit

Permalink
Add srem? for redis-rb compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenharman authored and sds committed Jan 15, 2024
1 parent 12272c2 commit c68fcb5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/mock_redis/set_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def srem(key, members)
end
end

def srem?(key, members)
res = srem(key, members)
res.is_a?(Numeric) ? res > 0 : res
end

def sscan(key, cursor, opts = {})
common_scan(smembers(key), cursor, opts)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/commands/srem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,20 @@
expect(@redises.srem(@key, [1, 2])).to eq(2)
end

context 'srem?' do
it 'returns true if member is in the set' do
expect(@redises.srem?(@key, 'bert')).to eq(true)
end

it 'returns false if member is not in the set' do
expect(@redises.srem?(@key, 'cookiemonster')).to eq(false)
end

it 'removes member from the set' do
@redises.srem?(@key, 'ernie')
expect(@redises.smembers(@key)).to eq(['bert'])
end
end

it_should_behave_like 'a set-only command'
end

0 comments on commit c68fcb5

Please sign in to comment.