I Want To Use Aioredis Connection Pool ,not Create New Connection In Every AsyncWebsocketConsumer.connect .Where Can I Put The Code
I want to use aioredis connection pool ,not create new connection in every AsyncWebsocketConsumer.connect .Where can I put the code. Now I create new connection in connect event ev
Solution 1:
Probably not the best solution, but you can do this
You app's __init__.py
from asgiref.sync import async_to_sync
redis = async_to_sync(aioredis.create_redis)('redis://localhost',encoding='utf-8')
Then in your consumer, you can import and use the existing redis connection
from . import redis
Post a Comment for "I Want To Use Aioredis Connection Pool ,not Create New Connection In Every AsyncWebsocketConsumer.connect .Where Can I Put The Code"