# -*- coding:utf-8 -*-
# @author: xrx
# @time: 2024/2/20 03:50
# @software: PyCharm
# desc:
import aioredis
async def connect_redis(redisUrl):
redisPool = aioredis.from_url(url=redisUrl, encoding="utf-8", decode_responses=True)
return redisPool
async def connPool():
redisUrl = 'redis://127.0.0.1:6379/4'
redisPool = await connect_redis(redisUrl)
val = await redisPool.get("review_0d2388b8338ea4a7c20db64c5b517556")
print(val)
print(type(val))
async def conn():
redisUrl = 'redis://127.0.0.1:6379/4'
redisPool = await connect_redis(redisUrl)
print(dir(redisPool))
async with redisPool.client() as conn:
val = await conn.get("review_0d2388b8338ea4a7c20db64c5b517556")
print(val)
print(type(val))
if __name__ == '__main__':
import asyncio
loop = asyncio.get_event_loop()
redis = loop.run_until_complete(conn())
loop.close()
【Python】aioredis异步使用Python解决方案
最新推荐文章于 2024-08-13 08:17:04 发布