diff --git a/lib/redis/distributed.rb b/lib/redis/distributed.rb index df4914831..7705bbe70 100644 --- a/lib/redis/distributed.rb +++ b/lib/redis/distributed.rb @@ -278,8 +278,18 @@ def get(key) end # Get the values of all the given keys. + # def mget(*keys) - raise CannotDistribute, :mget + m_nodes = keys.group_by { |key| node_for(key) } + + results = Hash[ + m_nodes.flat_map do |node, key_list| + values = node.mget(*key_list) + key_list.zip(values) + end + ] + + keys.map { |key| results[key] } end def mapped_mget(*keys) diff --git a/test/distributed_commands_on_strings_test.rb b/test/distributed_commands_on_strings_test.rb index ad83c12e5..9f4ed58d6 100644 --- a/test/distributed_commands_on_strings_test.rb +++ b/test/distributed_commands_on_strings_test.rb @@ -9,9 +9,11 @@ class TestDistributedCommandsOnStrings < Test::Unit::TestCase include Lint::Strings def test_mget - assert_raise Redis::Distributed::CannotDistribute do - r.mget("foo", "bar") - end + r.set("foo", "s1") + r.set("bar", "s2") + + assert_equal ["s1", "s2"] , r.mget("foo", "bar") + assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz") end def test_mget_mapped