Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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