(feat) Redis caching print exception statements when it fails

This commit is contained in:
ishaan-jaff 2023-10-25 11:29:47 -07:00
parent 7f7802ec1b
commit 5bd1b3968e

View file

@ -30,9 +30,14 @@ class RedisCache():
self.redis_client = redis.Redis(host=host, port=port, password=password)
def set_cache(self, key, value):
try:
self.redis_client.set(key, str(value))
except Exception as e:
# NON blocking - notify users Redis is throwing an exception
print("LiteLLM Caching: Got exception from REDIS: ", e)
def get_cache(self, key):
try:
# TODO convert this to a ModelResponse object
cached_response = self.redis_client.get(key)
if cached_response!=None:
@ -41,6 +46,9 @@ class RedisCache():
cached_response = json.loads(cached_response) # Convert string to dictionary
cached_response['cache'] = True # set cache-hit flag to True
return cached_response
except Exception as e:
# NON blocking - notify users Redis is throwing an exception
print("LiteLLM Caching: Got exception from REDIS: ", e)
class HostedCache():
def set_cache(self, key, value):