diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2010-03-16 10:29:41 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2010-03-16 10:29:41 -0700 |
commit | dbaef302fb95da2f4d30e5449891fc72eb0942d7 (patch) | |
tree | e47831d03ed734a9919eee486344b62397d73d76 /redis/client.py | |
parent | d240e77d58c2cf686bef925cab93b5970129aeb7 (diff) | |
download | redis-py-dbaef302fb95da2f4d30e5449891fc72eb0942d7.tar.gz |
HKEYS HVALS and HGETALL implemented
Diffstat (limited to 'redis/client.py')
-rw-r--r-- | redis/client.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index c5b3d52..006459d 100644 --- a/redis/client.py +++ b/redis/client.py @@ -153,6 +153,10 @@ def parse_info(response): info[key] = get_value(value) return info +def pairs_to_dict(response): + "Create a dict given a list of key/value pairs" + return dict(zip(response[::2], map(float, response[1::2]))) + def zset_score_pairs(response, **options): """ If ``withscores`` is specified in the options, return the response as @@ -202,6 +206,7 @@ class Redis(threading.local): string_keys_to_dict('ZRANGE ZRANGEBYSCORE ZREVRANGE', zset_score_pairs), { 'BGSAVE': lambda r: r == 'Background saving started', + 'HGETALL': lambda r: r and pairs_to_dict(r) or None, 'INFO': parse_info, 'LASTSAVE': timestamp_to_datetime, 'PING': lambda r: r == 'PONG', @@ -920,6 +925,14 @@ class Redis(threading.local): "Return the value of ``key`` within the hash ``name``" return self.format_bulk('HGET', name, key) + def hgetall(self, name): + "Return a Python dict of the hash's name/value pairs" + return self.format_inline('HGETALL', name) + + def hkeys(self, name): + "Return the list of keys within hash ``name``" + return self.format_inline('HKEYS', name) + def hset(self, name, key, value): """ Set ``key`` to ``value`` within hash ``name`` @@ -927,6 +940,9 @@ class Redis(threading.local): """ return self.format_multi_bulk('HSET', name, key, value) + def hvals(self, name): + "Return the list of values within hash ``name``" + return self.format_inline('HVALS', name) class Pipeline(Redis): """ |