diff options
author | Shaneal Manek <shaneal@greplin.com> | 2011-10-13 02:14:54 -0700 |
---|---|---|
committer | Shaneal Manek <shaneal@greplin.com> | 2011-10-13 02:14:54 -0700 |
commit | 0904a88b6a306fb455fb9381142706ba22260b2e (patch) | |
tree | 49a0fbcf8bd9138de01c31ee95b7a200c6ed79b4 /redis/client.py | |
parent | fb83cd05246a6c0ad297baa3d6571a97ecb86199 (diff) | |
download | redis-py-0904a88b6a306fb455fb9381142706ba22260b2e.tar.gz |
add a debug_object command - so we can get a key's size (among other things)
Diffstat (limited to 'redis/client.py')
-rw-r--r-- | redis/client.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index 948c1dc..dc6f60b 100644 --- a/redis/client.py +++ b/redis/client.py @@ -44,6 +44,20 @@ def dict_merge(*dicts): [merged.update(d) for d in 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 + def parse_info(response): "Parse the result of Redis's INFO command into a Python dict" info = {} @@ -151,6 +165,7 @@ class StrictRedis(object): 'CONFIG': parse_config, 'HGETALL': lambda r: r and pairs_to_dict(r) or {}, 'INFO': parse_info, + 'DEBUG' : parse_debug_object, 'LASTSAVE': timestamp_to_datetime, 'PING': lambda r: r == 'PONG', 'RANDOMKEY': lambda r: r and r or None, @@ -309,6 +324,10 @@ class StrictRedis(object): "Returns a dictionary containing information about the Redis server" 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) + def lastsave(self): """ Return a Python datetime object representing the last time the |