fix: Ensure consistent JSON serialization in sync Redis cache

This commit is contained in:
swarnabhasinha 2025-09-20 15:27:21 +05:30
parent 7e90f8a997
commit b6ce881793
No known key found for this signature in database
GPG key ID: 9B0C3EA24F21722E

View file

@ -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