Skip to content

Commit

Permalink
Allow mget to accept a block (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuk09 committed May 1, 2021
1 parent c129012 commit 622d0b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit 622d0b1

Please sign in to comment.