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 committed Jan 15, 2024
1 parent 3974db9 commit eefce05
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
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
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 eefce05

Please sign in to comment.