当前位置: 首页 > 工具软件 > asyncio-redis > 使用案例 >

asyncio异步编程之异步操作redis

白浩气
2023-12-01
import asyncio
import aioredis


async def operate():
    conn = await aioredis.StrictRedis(host="", port=xx, password="xx")
    test = await conn.get("test")
    print(test)
    await conn.set("name", "li")

    name = await conn.get("name")
    print(name)


tasks = [
    operate(),
    operate()
]

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    # loop.run_until_complete(operate())
    loop.run_until_complete(asyncio.wait(tasks))

 类似资料: