Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (30 sloc) 933 Bytes

RonS

A simplistic, asynchronous Redis client for Python Tornado.

Currently supports only SUBSCRIBE method (UNSUBSCRIBE is implicit).

Usage:

import rons
client = rons.Client()

class MainHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    @tornado.gen.engine
    @rons.save_generator
    def get(self):
        self.set_header('Content-Type', 'text/plain')
        self.write(" [*] Waiting....\n")
        self.flush()
        r = yield tornado.gen.Task( client.subscribe, 'test' )
        self.write(" [!] Got %r\n" % (r,))
        self.flush()
        self.finish()

    def on_connection_close(self):
        rons.stop_generator(self)

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    print " [*] Listening on http://localhost:8888/"
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()