Skip to content Skip to sidebar Skip to footer

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 importasync_to_syncredis= 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"