redis-py
redis-py copied to clipboard
Turn `acquire_connection` into a context manager
Pull Request check-list
Please make sure to review and check all of these items:
- [x] Do tests and lints pass with this change?
- [x] Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
- [ ] Is the new or changed code fully tested?
- [ ] Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
- [ ] Is there an example added to the examples folder (if applicable)?
- [x] Was the change added to CHANGES file?
NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
Description of change
Currently, the way connections are added back to the free pool is error prone and can run into issues during asyncio cancellations. By switching to a context manager, we ensure that the connections are always added while following python best practices.