Skip to content

Commit

Permalink
Merge branch 'sugar' of https://github.com/kmike/brukva into kmike-sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
evilkost committed Apr 13, 2011
2 parents 0b39a6e + 6a695a4 commit 39bf7da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 10 additions & 0 deletions brukva/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions demos/simple/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import tornado.ioloop
from brukva import adisp
import logging
from functools import partial


logging.basicConfig(level=logging.DEBUG)
Expand All @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 39bf7da

Please sign in to comment.