Created
January 11, 2016 13:48
-
-
Save asvetlov/756aaa58504155faf709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import asyncio | |
import aioredis | |
from aiohttp import web | |
import json | |
@asyncio.coroutine | |
def ulist(request): | |
data = yield from request.json() | |
dat = data['contacts'] | |
print(dat) | |
with (yield from request.app['redis']) as redis: | |
val = yield from redis.mget(*dat, encoding='utf-8') | |
return web.Response(text=json.dumps(val)) | |
@asyncio.coroutine | |
def init(loop): | |
app = web.Application(loop=loop) | |
app.router.add_route('POST', '/user_list', ulist) | |
app['redis'] = yield from aioredis.create_pool(('127.0.0.1', 6379), | |
db=1, | |
password='parol', | |
loop=loop) | |
srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8080) | |
print("Server started at http://127.0.0.1:8080") | |
return srv | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(init(loop)) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment