@@ -44,6 +44,20 @@ def dict_merge(*dicts):
44
44
[merged .update (d ) for d in dicts ]
45
45
return merged
46
46
47
+ def parse_debug_object (response ):
48
+ "Parse the results of Redis's DEBUG OBJECT command into a Python dict"
49
+ res = dict ([kv .split (':' ) for kv in ('type:' + response ).split ()])
50
+
51
+ # parse some expected int values from the string response
52
+ # note: this cmd isn't spec'd so these may not appear in all redis versions
53
+ possible_int_fields = ['refcount' , 'serializedlength' ,
54
+ 'lru' , 'lru_seconds_idle' ]
55
+ for field in possible_int_fields :
56
+ if field in res :
57
+ res [field ] = int (res [field ])
58
+
59
+ return res
60
+
47
61
def parse_info (response ):
48
62
"Parse the result of Redis's INFO command into a Python dict"
49
63
info = {}
@@ -151,6 +165,7 @@ class StrictRedis(object):
151
165
'CONFIG' : parse_config ,
152
166
'HGETALL' : lambda r : r and pairs_to_dict (r ) or {},
153
167
'INFO' : parse_info ,
168
+ 'DEBUG' : parse_debug_object ,
154
169
'LASTSAVE' : timestamp_to_datetime ,
155
170
'PING' : lambda r : r == 'PONG' ,
156
171
'RANDOMKEY' : lambda r : r and r or None ,
@@ -309,6 +324,10 @@ def info(self):
309
324
"Returns a dictionary containing information about the Redis server"
310
325
return self .execute_command ('INFO' )
311
326
327
+ def debug_object (self , key ):
328
+ """Returns version specific metainformation about a give key"""
329
+ return self .execute_command ('DEBUG' , 'OBJECT' , key )
330
+
312
331
def lastsave (self ):
313
332
"""
314
333
Return a Python datetime object representing the last time the
0 commit comments