Skip to content

Commit

Permalink
New command: info
Browse files Browse the repository at this point in the history
  • Loading branch information
kmerenkov committed May 19, 2010
1 parent b16ed67 commit ac0a896
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions brukva/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion brukva/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down

0 comments on commit ac0a896

Please sign in to comment.