diff options
author | Konstantin Merenkov <kmerenkov@gmail.com> | 2010-04-12 18:53:56 +0800 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2010-04-13 01:19:18 +0800 |
commit | edcb36a33d59fb5575bac0996152013b726d61c8 (patch) | |
tree | 227e7c9a27789d8eb2cf7597ae36e680b50c88cc | |
parent | 4dec96f235d3d1ef9fd1eb8a1549b75caae36c59 (diff) | |
download | redis-py-edcb36a33d59fb5575bac0996152013b726d61c8.tar.gz |
HMSET support
-rw-r--r-- | redis/client.py | 8 | ||||
-rw-r--r-- | tests/server_commands.py | 7 |
2 files changed, 14 insertions, 1 deletions
diff --git a/redis/client.py b/redis/client.py index 09a21fb..51986a0 100644 --- a/redis/client.py +++ b/redis/client.py @@ -190,7 +190,7 @@ class Redis(threading.local): """ RESPONSE_CALLBACKS = dict_merge( string_keys_to_dict( - 'AUTH DEL EXISTS EXPIRE HDEL HEXISTS MOVE MSETNX RENAMENX ' + 'AUTH DEL EXISTS EXPIRE HDEL HEXISTS HMSET MOVE MSETNX RENAMENX ' 'SADD SISMEMBER SMOVE SETNX SREM ZADD ZREM', bool ), @@ -1001,6 +1001,12 @@ class Redis(threading.local): """ return self.execute_command('HSET', name, key, value) + def hmset(self, key, mapping): + "Sets each key in the ``mapping`` dict to its corresponding value" + items = [] + [items.extend(pair) for pair in mapping.iteritems()] + return self.execute_command('HMSET', key, *items) + 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 da328ac..e67807e 100644 --- a/tests/server_commands.py +++ b/tests/server_commands.py @@ -716,6 +716,13 @@ class ServerCommandsTestCase(unittest.TestCase): # key inside of hash that doesn't exist returns null value self.assertEquals(self.client.hget('a', 'b'), None) + def test_hmset(self): + d = {'a': '1', 'b': '2', 'c': '3'} + self.assert_(self.client.hmset('foo', d)) + self.assertEqual(self.client.hgetall('foo'), d) + self.assertRaises(redis.ResponseError, self.client.hmset, 'foo', {}) + + def test_hdel(self): # key is not a hash self.client['a'] = 'a' |