diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2010-03-15 11:48:51 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2010-03-15 11:48:51 -0700 |
commit | d240e77d58c2cf686bef925cab93b5970129aeb7 (patch) | |
tree | 2be15ad8abebcbd6e45214d5905d56190c684d99 | |
parent | 9ada0de4a3fc25cbba246d63eea674fcce814a54 (diff) | |
download | redis-py-d240e77d58c2cf686bef925cab93b5970129aeb7.tar.gz |
HDEL implemented
-rw-r--r-- | redis/client.py | 8 | ||||
-rw-r--r-- | tests/server_commands.py | 23 |
2 files changed, 25 insertions, 6 deletions
diff --git a/redis/client.py b/redis/client.py index 969f601..c5b3d52 100644 --- a/redis/client.py +++ b/redis/client.py @@ -175,8 +175,8 @@ class Redis(threading.local): """ RESPONSE_CALLBACKS = dict_merge( string_keys_to_dict( - 'AUTH DEL EXISTS EXPIRE MOVE MSETNX RENAMENX SADD SISMEMBER SMOVE ' - 'SETNX SREM ZADD ZREM', + 'AUTH DEL EXISTS EXPIRE HDEL MOVE MSETNX RENAMENX ' + 'SADD SISMEMBER SMOVE SETNX SREM ZADD ZREM', bool ), string_keys_to_dict( @@ -912,6 +912,10 @@ class Redis(threading.local): #### HASH COMMANDS #### + def hdel(self, name, key): + "Delete ``key`` from hash ``name``" + return self.format_bulk('HDEL', name, key) + def hget(self, name, key): "Return the value of ``key`` within the hash ``name``" return self.format_bulk('HGET', name, key) diff --git a/tests/server_commands.py b/tests/server_commands.py index 0ddb7cb..c957381 100644 --- a/tests/server_commands.py +++ b/tests/server_commands.py @@ -697,11 +697,10 @@ class ServerCommandsTestCase(unittest.TestCase): self.client.hset(key, k, v) def test_hget_and_hset(self): - # TODO: add these back in, but right now they produce a crash bug. # key is not a hash - # self.client['a'] = 'a' - # self.assertRaises(redis.ResponseError, self.client.hget, 'a', 'a1') - # del self.client['a'] + self.client['a'] = 'a' + self.assertRaises(redis.ResponseError, self.client.hget, 'a', 'a1') + del self.client['a'] # no key self.assertEquals(self.client.hget('a', 'a1'), None) # real logic @@ -713,6 +712,22 @@ class ServerCommandsTestCase(unittest.TestCase): self.assertEquals(self.client.hget('a', 'a2'), '5') self.assertEquals(self.client.hset('a', 'a4', 4), 1) self.assertEquals(self.client.hget('a', 'a4'), '4') + # key inside of hash that doesn't exist returns null value + self.assertEquals(self.client.hget('a', 'b'), None) + + def test_hdel(self): + # key is not a hash + self.client['a'] = 'a' + self.assertRaises(redis.ResponseError, self.client.hdel, 'a', 'a1') + del self.client['a'] + # no key + self.assertEquals(self.client.hdel('a', 'a1'), False) + # real logic + self.make_hash('a', {'a1': 1, 'a2': 2, 'a3': 3}) + self.assertEquals(self.client.hget('a', 'a2'), '2') + self.assert_(self.client.hdel('a', 'a2')) + self.assertEquals(self.client.hget('a', 'a2'), None) + # SORT def test_sort_bad_key(self): |