diff --git a/redis/connection.py b/redis/connection.py index ace1ed8727..d905c6481b 100644 --- a/redis/connection.py +++ b/redis/connection.py @@ -1378,6 +1378,7 @@ def __init__( # will notice the first thread already did the work and simply # release the lock. self._fork_lock = threading.Lock() + self._lock = threading.Lock() self.reset() def __repr__(self) -> (str, str): @@ -1395,7 +1396,6 @@ def get_protocol(self): return self.connection_kwargs.get("protocol", None) def reset(self) -> None: - self._lock = threading.Lock() self._created_connections = 0 self._available_connections = [] self._in_use_connections = set() diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index dee7c554d3..118294ee1b 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -7,10 +7,16 @@ import pytest import redis -from redis.connection import to_bool -from redis.utils import SSL_AVAILABLE - -from .conftest import _get_client, skip_if_redis_enterprise, skip_if_server_version_lt +from redis.cache import CacheConfig +from redis.connection import CacheProxyConnection, Connection, to_bool +from redis.utils import HIREDIS_AVAILABLE, SSL_AVAILABLE + +from .conftest import ( + _get_client, + skip_if_redis_enterprise, + skip_if_resp_version, + skip_if_server_version_lt, +) from .test_pubsub import wait_for_message @@ -196,6 +202,20 @@ def test_repr_contains_db_info_unix(self): expected = "path=abc,db=0,client_name=test-client" assert expected in repr(pool) + @pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only") + @pytest.mark.onlynoncluster + @skip_if_resp_version(2) + @skip_if_server_version_lt("7.4.0") + def test_initialise_pool_with_cache(self, master_host): + pool = redis.BlockingConnectionPool( + connection_class=Connection, + host=master_host[0], + port=master_host[1], + protocol=3, + cache_config=CacheConfig(), + ) + assert isinstance(pool.get_connection("_"), CacheProxyConnection) + class TestConnectionPoolURLParsing: def test_hostname(self):