diff options
-rw-r--r-- | redis/client.py | 4 | ||||
-rw-r--r-- | tests/server_commands.py | 11 |
2 files changed, 15 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index 51986a0..a696e2b 100644 --- a/redis/client.py +++ b/redis/client.py @@ -1007,6 +1007,10 @@ class Redis(threading.local): [items.extend(pair) for pair in mapping.iteritems()] return self.execute_command('HMSET', key, *items) + def hmget(self, name, keys): + "Returns a list of values ordered identically to ``keys``" + return self.execute_command('HMGET', name, *keys) + def hvals(self, name): "Return the list of values within hash ``name``" return self.execute_command('HVALS', name) diff --git a/tests/server_commands.py b/tests/server_commands.py index 45b82c7..e90d680 100644 --- a/tests/server_commands.py +++ b/tests/server_commands.py @@ -722,6 +722,17 @@ class ServerCommandsTestCase(unittest.TestCase): self.assertEqual(self.client.hgetall('foo'), d) self.assertRaises(redis.ResponseError, self.client.hmset, 'foo', {}) + def test_hmget(self): + d = {'a': 1, 'b': 2, 'c': 3} + self.assert_(self.client.hmset('foo', d)) + self.assertEqual(self.client.hmget('foo', ['a', 'b', 'c']), ['1', '2', '3']) + self.assertEqual(self.client.hmget('foo', ['a', 'c']), ['1', '3']) + + def test_hmget_empty(self): + self.assertEqual(self.client.hmget('foo', ['a', 'b']), [None, None]) + + def test_hmget_no_keys(self): + self.assertRaises(redis.ResponseError, self.client.hmget, 'foo', []) def test_hdel(self): # key is not a hash |