MCPcopy
hub / github.com/langroid/langroid / redis_client

Method redis_client

langroid/cachedb/redis_cachedb.py:65–74  ·  view source on GitHub ↗

Cleanly open and close a redis client, avoids max clients exceeded error

(self)

Source from the content-addressed store, hash-verified

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

Callers 7

close_all_connectionsMethod · 0.95
clearMethod · 0.95
clear_allMethod · 0.95
storeMethod · 0.95
retrieveMethod · 0.95
delete_keysMethod · 0.95
delete_keys_patternMethod · 0.95

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected