evilkost / brukva

Asynchronous Redis client that works within Tornado IO loop.
Other
265 stars 33 forks source link

Add example #14

Open recoyou opened 13 years ago

recoyou commented 13 years ago

Please add examples, Its takes few hours to understand that module works:

On Windows: c = brukva.Client(host = '127.0.0.1')

Example: import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web

from tornado.options import define, options

define("port", default=8888, help="run on the given port", type=int)

import logging import brukva from brukva import adisp

logging.basicConfig(level=logging.DEBUG) log = logging.getLogger('app')

c = brukva.Client() c.connect()

class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous @adisp.process def get(self): yield c.async.set('hello', 'Hello, world') foo = yield c.async.get('hello') self.write(foo) self.finish()

def main(): tornado.options.parse_command_line() application = tornado.web.Application([ (r"/", MainHandler), ]) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()

if name == "main": main()