Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: client as context manager #125

Open
clbarnes opened this issue Aug 2, 2019 · 1 comment
Open

Feature request: client as context manager #125

clbarnes opened this issue Aug 2, 2019 · 1 comment

Comments

@clbarnes
Copy link

clbarnes commented Aug 2, 2019

There are a few cases where redislite instances are useful to spin up during the execution of a script, and then make sure they're cleared up afterwards (tests etc.). One can manually shutdown the server and/or del the instance, which can be done in a try/except to be error-tolerant, but this is a perfect use case for a context manager which would call _cleanup on __exit__.

It could be as simple as adding

class RedisMixin(object):
    ...

    def __enter__(self):
        return self

    def __exit__(exc_type, exc_val, exc_tb):
        self._cleanup()
        # self.shutdown()  # possibly

Although we'd probably want to make sure we didn't cleanup/ shutdown a server we didn't start.

Somewhat related to #97

@dwighthubbard
Copy link
Contributor

Yes, that sounds like a good idea to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants