Permalink
Browse files

Merge pull request #301 from aouyar/master

Implement support for passing an arg to INFO command
  • Loading branch information...
2 parents 9ee121d + 14205a4 commit 79194999943ebdab51d8778d331e26bf9f9e1ce8 Andy McCurdy committed Nov 30, 2012
Showing with 26 additions and 18 deletions.
  1. +26 −18 redis/client.py
View
@@ -88,27 +88,24 @@ def parse_info(response):
def get_value(value):
if ',' not in value or '=' not in value:
- return value
-
- sub_dict = {}
- for item in value.split(','):
- k, v = item.rsplit('=', 1)
try:
- sub_dict[k] = int(v)
+ if '.' in value:
+ return float(value)
+ else:
+ return int(value)
except ValueError:
- sub_dict[k] = v
- return sub_dict
+ return value
+ else:
+ sub_dict = {}
+ for item in value.split(','):
+ k, v = item.rsplit('=', 1)
+ sub_dict[k] = get_value(v)
+ return sub_dict
for line in response.splitlines():
if line and not line.startswith('#'):
key, value = line.split(':')
- try:
- if '.' in value:
- info[key] = float(value)
- else:
- info[key] = int(value)
- except ValueError:
- info[key] = get_value(value)
+ info[key] = get_value(value)
return info
@@ -433,9 +430,20 @@ def flushdb(self):
"Delete all keys in the current database"
return self.execute_command('FLUSHDB')
- def info(self):
- "Returns a dictionary containing information about the Redis server"
- return self.execute_command('INFO')
+ def info(self, section=None):
+ """
+ Returns a dictionary containing information about the Redis server
+
+ The ``section`` option can be used to select a specific section
+ of information
+
+ The section option is not supported by older versions of Redis Server,
+ and will generate ResponseError
+ """
+ if section is None:
+ return self.execute_command('INFO')
+ else:
+ return self.execute_command('INFO', section)
def lastsave(self):
"""

0 comments on commit 7919499

Please sign in to comment.