Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add srem? for redis-rb compatibility #294

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading