@@ -60,6 +60,12 @@ def parse_debug_object(response):
60
60
61
61
return response
62
62
63
+ def parse_object (response , infotype ):
64
+ "Parse the results of an OBJECT command"
65
+ if infotype in ('idletime' , 'refcount' ):
66
+ return int (response )
67
+ return response
68
+
63
69
def parse_info (response ):
64
70
"Parse the result of Redis's INFO command into a Python dict"
65
71
info = {}
@@ -166,10 +172,11 @@ class StrictRedis(object):
166
172
'BGSAVE' : lambda r : r == 'Background saving started' ,
167
173
'BRPOPLPUSH' : lambda r : r and r or None ,
168
174
'CONFIG' : parse_config ,
175
+ 'DEBUG' : parse_debug_object ,
169
176
'HGETALL' : lambda r : r and pairs_to_dict (r ) or {},
170
177
'INFO' : parse_info ,
171
- 'DEBUG' : parse_debug_object ,
172
178
'LASTSAVE' : timestamp_to_datetime ,
179
+ 'OBJECT' : parse_object ,
173
180
'PING' : lambda r : r == 'PONG' ,
174
181
'RANDOMKEY' : lambda r : r and r or None ,
175
182
}
@@ -306,6 +313,10 @@ def dbsize(self):
306
313
"Returns the number of keys in the current database"
307
314
return self .execute_command ('DBSIZE' )
308
315
316
+ def debug_object (self , key ):
317
+ "Returns version specific metainformation about a give key"
318
+ return self .execute_command ('DEBUG' , 'OBJECT' , key )
319
+
309
320
def delete (self , * names ):
310
321
"Delete one or more keys specified by ``names``"
311
322
return self .execute_command ('DEL' , * names )
@@ -327,17 +338,17 @@ def info(self):
327
338
"Returns a dictionary containing information about the Redis server"
328
339
return self .execute_command ('INFO' )
329
340
330
- def debug_object (self , key ):
331
- "Returns version specific metainformation about a give key"
332
- return self .execute_command ('DEBUG' , 'OBJECT' , key )
333
-
334
341
def lastsave (self ):
335
342
"""
336
343
Return a Python datetime object representing the last time the
337
344
Redis database was saved to disk
338
345
"""
339
346
return self .execute_command ('LASTSAVE' )
340
347
348
+ def object (self , infotype , key ):
349
+ "Return the encoding, idletime, or refcount about the key"
350
+ return self .execute_command ('OBJECT' , infotype , key , infotype = infotype )
351
+
341
352
def ping (self ):
342
353
"Ping the Redis server"
343
354
return self .execute_command ('PING' )
0 commit comments