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

Allow mget to accept a block #210

Merged
merged 1 commit into from May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/mock_redis/string_methods.rb
Expand Up @@ -154,14 +154,16 @@ def incrbyfloat(key, n)
new_value
end

def mget(*keys)
def mget(*keys, &blk)
keys.flatten!

assert_has_args(keys, 'mget')

keys.map do |key|
data = keys.map do |key|
get(key) if stringy?(key)
end

blk ? blk.call(data) : data
end

def mapped_mget(*keys)
Expand Down
6 changes: 6 additions & 0 deletions spec/commands/mget_spec.rb
Expand Up @@ -56,4 +56,10 @@
end.should raise_error(Redis::CommandError)
end
end

context 'emulate block' do
it 'returns an array of values' do
@redises.mget(@key1, @key2) { |values| values.map(&:to_i) }.should == [1, 2]
end
end
end