Source

tornadis / test.py

Full commit
#!/usr/bin/env python
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.escape
from tornado.options import define, options

from redis import RedisTornado
import swirl

define("port", default=8080, help="run on the given port", type=int)
define("debug", default=False, help="run in debug")

settings = {'debug' : options.debug }

r = RedisTornado()

class GetHandler(tornado.web.RequestHandler):
    @swirl.asynchronous
    def get(self):
        value = (yield lambda cb : r.get('foo', cb)) or 'Nope'
        self.write(value)

class SetHandler(tornado.web.RequestHandler):
    @swirl.asynchronous
    def get(self):
        value = yield lambda cb: r.set('foo', 'bar', cb)
        self.write(str(value))


def main():
    tornado.options.parse_command_line()
    application = tornado.web.Application([
        (r'/get',   GetHandler),
        (r'/set',   SetHandler),
    ], **settings)
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()


if __name__ == "__main__":
    main()