Skip to content

Instantly share code, notes, and snippets.

@singulared
Last active February 26, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save singulared/b65d2d41b516932f97aac230c2fb4bef to your computer and use it in GitHub Desktop.
Save singulared/b65d2d41b516932f97aac230c2fb4bef to your computer and use it in GitHub Desktop.
aiohttp benchmark
import aioredis
from aiohttp import web
async def init(app):
print('redis connecton')
app['redis'] = await aioredis.create_redis(
'redis://localhost', loop=app.loop)
async def deinit(app):
print('close redis')
app['redis'].close()
await app['redis'].wait_closed()
async def hello(request):
counter = await request.app['redis'].incr('test_key')
return web.Response(text='{{"result": {}}}'.format(counter),
content_type='application/json')
app = web.Application()
app.on_startup.append(init)
app.on_cleanup.append(deinit)
app.router.add_get('/', hello)
web.run_app(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment