Cleanly open and close a redis client, avoids max clients exceeded error
(self)
| 63 | |
| 64 | @contextmanager # type: ignore |
| 65 | def redis_client(self) -> AbstractContextManager[T]: # type: ignore |
| 66 | """Cleanly open and close a redis client, avoids max clients exceeded error""" |
| 67 | if isinstance(self.pool, fakeredis.FakeStrictRedis): |
| 68 | yield self.pool |
| 69 | else: |
| 70 | client: T = redis.Redis(connection_pool=self.pool) |
| 71 | try: |
| 72 | yield client |
| 73 | finally: |
| 74 | client.close() |
| 75 | |
| 76 | def close_all_connections(self) -> None: |
| 77 | with self.redis_client() as client: # type: ignore |
no test coverage detected