From b6ce881793bb5c4422ae2ca223ed7df2ed567a44 Mon Sep 17 00:00:00 2001 From: swarnabhasinha Date: Sat, 20 Sep 2025 15:27:21 +0530 Subject: [PATCH] fix: Ensure consistent JSON serialization in sync Redis cache --- litellm/caching/redis_cache.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/litellm/caching/redis_cache.py b/litellm/caching/redis_cache.py index c09a407d782..62b99023a21 100644 --- a/litellm/caching/redis_cache.py +++ b/litellm/caching/redis_cache.py @@ -217,11 +217,8 @@ class RedisCache(BaseCache): key = self.check_and_fix_namespace(key=key) try: start_time = time.time() - # Convert value to JSON string to handle complex objects like timedelta - if isinstance(value, (dict, list)) or hasattr(value, "__dict__"): - serialized_value = json.dumps(value, cls=TimedeltaJSONEncoder) - else: - serialized_value = str(value) + # Always use JSON serialization for consistency with async method + serialized_value = json.dumps(value, cls=TimedeltaJSONEncoder) self.redis_client.set(name=key, value=serialized_value, ex=ttl) end_time = time.time() _duration = end_time - start_time