Async vs Sync
*.pyc |
hiredis==0.2.0 | |
redis==2.10.5 | |
tornado==4.4.2 | |
tornado-redis==2.4.18 | |
uWSGI==2.0.14 |
#!/bin/sh | |
exec uwsgi -w uwsgi_fast:app --http :8000 --http-keepalive &> /dev/null |
import tornado.ioloop | |
import tornado.web | |
from tornado.gen import coroutine | |
from redis import StrictRedis | |
client = StrictRedis() | |
class MainHandler(tornado.web.RequestHandler): | |
@coroutine | |
def get(self): | |
data = client.mget('key1', 'key2', 'key3') | |
self.write({'result': data}) | |
def make_app(): | |
return tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
app = make_app() | |
app.listen(8000) | |
tornado.ioloop.IOLoop.current().start() |
import tornado.ioloop | |
import tornado.web | |
from tornado.gen import coroutine, Task | |
import tornadoredis | |
c = tornadoredis.Client() | |
c.connect() | |
class MainHandler(tornado.web.RequestHandler): | |
@coroutine | |
def get(self): | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
data = yield Task(c.mget, ['key1', 'key2', 'key3']) | |
self.write({'result': data}) | |
def make_app(): | |
return tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
if __name__ == "__main__": | |
app = make_app() | |
app.listen(8000) | |
tornado.ioloop.IOLoop.current().start() |
from redis import StrictRedis | |
import json | |
client = StrictRedis() | |
def app(env, start_response): | |
start_response('200 OK', [('Content-Type','text/html')]) | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
data = client.mget('key1', 'key2', 'key3') | |
return [json.dumps({'result': data})] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment