Open eoghanmurray opened 1 year ago
https://redis.readthedocs.io/en/stable/examples/asyncio_examples.html#Connecting-and-Disconnecting "Utilizing asyncio Redis requires an explicit disconnect of the connection since there is no asyncio deconstructor magic method."
I'm wondering if the above line makes sense if it's true that the __del__
function could serve the purpose as a deconstructor?
I think to fix your problem, you can just use the async context manager, it calls the aclose
async def endpoint(request=False, source=''):
async with RedisCluster(
REDIS_CX[0], REDIS_CX[1], password=REDIS_PWD,
decode_responses=decode_responses,
) as red:
red.do_stuff()
return web.json_response(ret)
Creating a connection every request seems a little heavy handed in my opinion, perhaps opening a connection and storing the reference on web server and then call aclose on server shutdown might be better?
I've come to the library from
aredis
and running my same code, a web application built on aiohttp. I'm wondering why this library warns if a redis connection has not been closed in the__del__
function, rather than just closing it?Although it now is obvious, It took me a while to track down what exactly was triggering the warning; I previously didn't know that connections were expected to
await aclose
So my questions are:
RedisCluster
with each request; should I be opening up a pool first? The warning implies that these operations are more expensive than I was thinkingawait red.aclose()
there potentially be expensive and slow down the response slightly?__del__
function (presumably triggered by garbage collection) just go ahead and close the connection for me without emitting a warning?I'd be happy to update docs etc. if there are changes needed.