diff options
author | andy <andy@andymccurdy.com> | 2011-10-24 12:43:30 -0700 |
---|---|---|
committer | andy <andy@andymccurdy.com> | 2011-10-24 12:43:30 -0700 |
commit | 4e18978b8eb4c8d70e26ba8a2c9209454495023b (patch) | |
tree | 92a993511c4c5f60be0888c87a8eff9f6cb8706c | |
parent | 86fab8c48a1091a89deb4334e320fe2fe8d1a6b5 (diff) | |
download | redis-py-4e18978b8eb4c8d70e26ba8a2c9209454495023b.tar.gz |
Fix spacing from DEBUG OBJECT pull request.
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | redis/client.py | 33 |
2 files changed, 19 insertions, 15 deletions
@@ -1,4 +1,5 @@ * 2.4.10 (in development) + * Added the DEBUG OBJECT command. * Added __del__ methods for classes that hold on to resources that need to be cleaned up. This should prevent resource leakage when these objects leave scope due to misuse or unhandled exceptions. Thanks David Wolever diff --git a/redis/client.py b/redis/client.py index 5a03231..826f86f 100644 --- a/redis/client.py +++ b/redis/client.py @@ -45,22 +45,25 @@ def dict_merge(*dicts): return merged def parse_debug_object(response): - "Parse the results of Redis's DEBUG OBJECT command into a Python dict" - res = dict([kv.split(':') for kv in ('type:' + response).split()]) - - # parse some expected int values from the string response - # note: this cmd isn't spec'd so these may not appear in all redis versions - possible_int_fields = ['refcount', 'serializedlength', - 'lru', 'lru_seconds_idle'] - for field in possible_int_fields: - if field in res: - res[field] = int(res[field]) - - return res + "Parse the results of Redis's DEBUG OBJECT command into a Python dict" + # The 'type' of the object is the first item in the response, but isn't + # prefixed with a name + response = 'type:' + response + response = dict([kv.split(':') for kv in response.split()]) + + # parse some expected int values from the string response + # note: this cmd isn't spec'd so these may not appear in all redis versions + int_fields = ('refcount', 'serializedlength', 'lru', 'lru_seconds_idle') + for field in int_fields: + if field in response: + response[field] = int(response[field]) + + return response def parse_info(response): "Parse the result of Redis's INFO command into a Python dict" info = {} + def get_value(value): if ',' not in value: return value @@ -165,7 +168,7 @@ class StrictRedis(object): 'CONFIG': parse_config, 'HGETALL': lambda r: r and pairs_to_dict(r) or {}, 'INFO': parse_info, - 'DEBUG' : parse_debug_object, + 'DEBUG': parse_debug_object, 'LASTSAVE': timestamp_to_datetime, 'PING': lambda r: r == 'PONG', 'RANDOMKEY': lambda r: r and r or None, @@ -325,8 +328,8 @@ class StrictRedis(object): return self.execute_command('INFO') def debug_object(self, key): - """Returns version specific metainformation about a give key""" - return self.execute_command('DEBUG', 'OBJECT', key) + "Returns version specific metainformation about a give key" + return self.execute_command('DEBUG', 'OBJECT', key) def lastsave(self): """ |