diff --git a/brukva/client.py b/brukva/client.py index dd04173..f810457 100644 --- a/brukva/client.py +++ b/brukva/client.py @@ -220,11 +220,21 @@ def get_value(value): def reply_ttl(r, *args, **kwargs): return r != -1 and r or None + +class _AsyncWrapper(object): + def __init__(self, obj): + self.obj = obj + + def __getattr__(self, item): + return async(getattr(self.obj, item), cbname='callbacks') + + class Client(object): def __init__(self, host='localhost', port=6379, password=None, reconnect=False, io_loop=None): self._io_loop = io_loop or IOLoop.instance() self.connection = Connection(host, port, self.on_reconnect, io_loop=self._io_loop) + self.async = _AsyncWrapper(self) self.queue = [] self.current_cmd_line = None self.subscribed = False diff --git a/demos/simple/app.py b/demos/simple/app.py index 1845313..83265ff 100644 --- a/demos/simple/app.py +++ b/demos/simple/app.py @@ -5,7 +5,6 @@ import tornado.ioloop from brukva import adisp import logging -from functools import partial logging.basicConfig(level=logging.DEBUG) @@ -18,11 +17,7 @@ def on_set(result): - (error, data) = result - log.debug("set result: %s" % (error or data,)) - - -async = partial(adisp.async, cbname='callbacks') + log.debug("set result: %s" % result) c.set('foo', 'Lorem ipsum #1', on_set) @@ -34,9 +29,9 @@ class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous @adisp.process def get(self): - (_, foo) = yield async(c.get)('foo') - (_, bar) = yield async(c.get)('bar') - (_, zar) = yield async(c.get)('zar') + foo = yield c.async.get('foo') + bar = yield c.async.get('bar') + zar = yield c.async.get('zar') self.set_header('Content-Type', 'text/html') self.render("template.html", title="Simple demo", foo=foo, bar=bar, zar=zar)