From 796d05f855f00e0fda05129dd62c39e8670283e7 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 24 Mar 2009 11:28:34 +0100 Subject: [PATCH] Python client library updated, thanks to Ludo! --- client-libraries/python/redis.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/client-libraries/python/redis.py b/client-libraries/python/redis.py index e844f812b..954c27690 100644 --- a/client-libraries/python/redis.py +++ b/client-libraries/python/redis.py @@ -140,6 +140,19 @@ class Redis(object): self._write('GET %s\r\n' % name) return self._get_value() + def mget(self, *args): + """ + >>> r = Redis() + >>> r.set('a', 'pippo'), r.set('b', 15), r.set('c', '\\r\\naaa\\nbbb\\r\\ncccc\\nddd\\r\\n'), r.set('d', '\\r\\n') + ('OK', 'OK', 'OK', 'OK') + >>> r.mget('a', 'b', 'c', 'd') + ['pippo', '15', '\\r\\naaa\\nbbb\\r\\ncccc\\nddd\\r\\n', '\\r\\n'] + >>> + """ + self.connect() + self._write('MGET %s\r\n' % ' '.join(args)) + return self._get_multi_response() + def incr(self, name, amount=1): """ >>> r = Redis() @@ -827,6 +840,26 @@ class Redis(object): self._write('%s\r\n' % ('FLUSHALL' if all_dbs else 'FLUSHDB')) return self._get_simple_response() + def info(self): + """ + >>> r = Redis() + >>> info = r.info() + >>> info and isinstance(info, dict) + True + >>> isinstance(info.get('connected_clients'), int) + True + >>> + """ + self.connect() + self._write('INFO\r\n') + info = dict() + for l in self._get_value().split('\r\n'): + if not l: + continue + k, v = l.split(':', 1) + info[k] = int(v) if v.isdigit() else v + return info + def _get_value(self, negative_as_nil=False): data = self._read().strip() if data == 'nil' or (negative_as_nil and data == '-1'):