[Optimize] Optimize code in caching file

This commit is contained in:
Rahul Kataria 2024-05-12 17:04:18 +05:30
parent 3f146b2c7e
commit 689221b5c7

View file

@ -373,11 +373,12 @@ class RedisCache(BaseCache):
print_verbose( print_verbose(
f"Set ASYNC Redis Cache PIPELINE: key: {cache_key}\nValue {cache_value}\nttl={ttl}" f"Set ASYNC Redis Cache PIPELINE: key: {cache_key}\nValue {cache_value}\nttl={ttl}"
) )
json_cache_value = json.dumps(cache_value)
# Set the value with a TTL if it's provided. # Set the value with a TTL if it's provided.
if ttl is not None: if ttl is not None:
pipe.setex(cache_key, ttl, json.dumps(cache_value)) pipe.setex(cache_key, ttl, json_cache_value)
else: else:
pipe.set(cache_key, json.dumps(cache_value)) pipe.set(cache_key, json_cache_value)
# Execute the pipeline and return the results. # Execute the pipeline and return the results.
results = await pipe.execute() results = await pipe.execute()