From ac0a89617986045d7d0794be87402b9d1da60971 Mon Sep 17 00:00:00 2001 From: Konstantin Merenkov Date: Wed, 19 May 2010 19:24:03 +0400 Subject: [PATCH] New command: info --- brukva/client.py | 25 +++++++++++++++++++++++++ brukva/exceptions.py | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/brukva/client.py b/brukva/client.py index cef9f3c..49a064b 100644 --- a/brukva/client.py +++ b/brukva/client.py @@ -21,6 +21,27 @@ def dict_merge(*dicts): [merged.update(d) for d in dicts] return merged +def parse_info(response): + info = {} + def get_value(value): + if ',' not in value: + return value + sub_dict = {} + for item in value.split(','): + k, v = item.split('=') + try: + sub_dict[k] = int(v) + except ValueError: + sub_dict[k] = v + return sub_dict + for line in response.splitlines(): + key, value = line.split(':') + try: + info[key] = int(value) + except ValueError: + info[key] = get_value(value) + return info + class Connection(object): def __init__(self, host, port, timeout=None, io_loop=None): @@ -92,6 +113,7 @@ def __init__(self, host='localhost', port=6379, io_loop=None): {'PING': lambda r: r == 'PONG'}, {'LASTSAVE': lambda t: datetime.fromtimestamp(int(t))}, {'TTL': lambda r: r != -1 and r or None}, + {'INFO': parse_info}, ) def zset_score_pairs(self, response): @@ -239,6 +261,9 @@ def flushdb(self, callbacks=None): def ping(self, callbacks=None): self.execute_command('PING', callbacks) + def info(self, callbacks=None): + self.execute_command('INFO', callbacks) + def select(self, db, callbacks=None): self.execute_command('SELECT', callbacks, db) diff --git a/brukva/exceptions.py b/brukva/exceptions.py index fa4e92b..bc5ae08 100644 --- a/brukva/exceptions.py +++ b/brukva/exceptions.py @@ -12,7 +12,7 @@ def __init__(self, task, message): self.message = message def __repr__(self): - return 'ResponseError (on %s [%s, %s]): %s' % (self.task.command, self.task.args, self.task.kwargs, self.message) + return 'ResponseError (on %s [%s, %s]): %s' % (self.task.command, self.task.command_args, self.task.command_kwargs, self.message) __str__ = __repr__