diff --git a/redis/_cache.py b/redis/_cache.py index 90288383d6..79182ce797 100644 --- a/redis/_cache.py +++ b/redis/_cache.py @@ -159,6 +159,8 @@ class EvictionPolicy(Enum): _CTIME = "ctime" _ACCESS_COUNT = "access_count" +IMMUTABLES = (bytes, str, int, float, bool, type(None), tuple) + class AbstractCache(ABC): """ @@ -267,7 +269,12 @@ def get(self, command: Union[str, Sequence[str]]) -> ResponseT: self.delete_command(command) return self._update_access(command) - return copy.deepcopy(self.cache[command]["response"]) + response = self.cache[command]["response"] + return ( + response + if isinstance(response, IMMUTABLES) + else copy.deepcopy(response) + ) def delete_command(self, command: Union[str, Sequence[str]]): """ diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 1845b7252f..5ced8a1f09 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -287,7 +287,7 @@ def __init__( "decode_responses": decode_responses, "retry_on_timeout": retry_on_timeout, "retry_on_error": retry_on_error, - "retry": copy.deepcopy(retry), + "retry": retry if retry is None else copy.deepcopy(retry), "max_connections": max_connections, "health_check_interval": health_check_interval, "client_name": client_name, diff --git a/redis/client.py b/redis/client.py index 02fc724322..1dca886378 100755 --- a/redis/client.py +++ b/redis/client.py @@ -265,7 +265,7 @@ def __init__( "encoding_errors": encoding_errors, "decode_responses": decode_responses, "retry_on_error": retry_on_error, - "retry": copy.deepcopy(retry), + "retry": retry if retry is None else copy.deepcopy(retry), "max_connections": max_connections, "health_check_interval": health_check_interval, "client_name": client_name,