redislite
redislite copied to clipboard
Feature request: client as context manager
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
Yes, that sounds like a good idea to me.