summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
authorandy <andy@andymccurdy.com>2011-10-21 16:31:53 -0700
committerandy <andy@andymccurdy.com>2011-10-21 16:31:53 -0700
commit86fab8c48a1091a89deb4334e320fe2fe8d1a6b5 (patch)
tree4d92cb51ebd52fa4b7b48d8be81e65b3a6505fff /redis/client.py
parentf6bb11cd878f99b520b0e167e481ea6488306771 (diff)
parent76ffc5371800c4bbee87a00c95cb16a2f77738ca (diff)
downloadredis-py-86fab8c48a1091a89deb4334e320fe2fe8d1a6b5.tar.gz
Merge branch 'master' of github.com:andymccurdy/redis-py
Diffstat (limited to 'redis/client.py')
-rw-r--r--redis/client.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py
index 15caed4..5a03231 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