From 210d51258b403aa3d8a6a78d9b8a22ff821f20aa Mon Sep 17 00:00:00 2001 From: holys Date: Wed, 3 Sep 2014 22:00:31 +0800 Subject: [PATCH] info bug fix --- client/ledis-py/ledis/client.py | 39 ++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/client/ledis-py/ledis/client.py b/client/ledis-py/ledis/client.py index 034f2e3..5547d6a 100644 --- a/client/ledis-py/ledis/client.py +++ b/client/ledis-py/ledis/client.py @@ -64,6 +64,30 @@ def int_or_none(response): return int(response) +def parse_info(response): + + info = {} + response = nativestr(response) + + def get_value(value): + if ',' not in value or '=' not in value: + try: + if '.' in value: + return float(value) + else: + return int(value) + except ValueError: + return value + + for line in response.splitlines(): + if line and not line.startswith('#'): + if line.find(':') != -1: + key, value = line.split(':', 1) + info[key] = get_value(value) + + return info + + class Ledis(object): """ Implementation of the Redis protocol. @@ -111,7 +135,8 @@ class Ledis(object): 'HGETALL': lambda r: r and pairs_to_dict(r) or {}, 'PING': lambda r: nativestr(r) == 'PONG', 'SET': lambda r: r and nativestr(r) == 'OK', - }, + 'INFO': parse_info, + } ) @@ -219,8 +244,15 @@ class Ledis(object): db = 0 return self.execute_command('SELECT', db) - def info(self, section): - return self.execute_command('PING', section) + def info(self, section=None): + """ + Return + """ + + if section is None: + return self.execute_command("INFO") + else: + return self.execute_command('INFO', section) def flushall(self): return self.execute_command('FLUSHALL') @@ -924,6 +956,7 @@ class Ledis(object): def scriptflush(self): return self.execute_command('SCRIPT', 'FLUSH') + class Transaction(Ledis): def __init__(self, connection_pool, response_callbacks): self.connection_pool = connection_pool