From d000b161769e77607132a13857b5ea24d51c1274 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Mon, 6 Jan 2025 15:05:14 +0200 Subject: [PATCH 1/4] Moved self._lock initialisation to Pool constructor --- redis/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() From f2e590de57ff03f1fa1ca4529b42d344667d0402 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Mon, 6 Jan 2025 15:20:00 +0200 Subject: [PATCH 2/4] Added test case --- tests/test_connection_pool.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index dee7c554d3..2aca7648e6 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -7,7 +7,8 @@ import pytest import redis -from redis.connection import to_bool +from redis.cache import CacheConfig +from redis.connection import to_bool, CacheProxyConnection, Connection from redis.utils import SSL_AVAILABLE from .conftest import _get_client, skip_if_redis_enterprise, skip_if_server_version_lt @@ -196,6 +197,16 @@ def test_repr_contains_db_info_unix(self): expected = "path=abc,db=0,client_name=test-client" assert expected in repr(pool) + 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): From 22609a2996d9e3480cb925fbe2baafe9c8835f7f Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Mon, 6 Jan 2025 15:21:55 +0200 Subject: [PATCH 3/4] Codestyle fixes --- tests/test_connection_pool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index 2aca7648e6..1ae31ae37c 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -8,7 +8,7 @@ import pytest import redis from redis.cache import CacheConfig -from redis.connection import to_bool, CacheProxyConnection, Connection +from redis.connection import CacheProxyConnection, Connection, to_bool from redis.utils import SSL_AVAILABLE from .conftest import _get_client, skip_if_redis_enterprise, skip_if_server_version_lt From c3f964a6f48895f453fea99b359fcf3ff26f73d9 Mon Sep 17 00:00:00 2001 From: vladvildanov Date: Mon, 6 Jan 2025 15:27:49 +0200 Subject: [PATCH 4/4] Added correct annotations --- tests/test_connection_pool.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py index 1ae31ae37c..118294ee1b 100644 --- a/tests/test_connection_pool.py +++ b/tests/test_connection_pool.py @@ -9,9 +9,14 @@ import redis from redis.cache import CacheConfig from redis.connection import CacheProxyConnection, Connection, to_bool -from redis.utils import SSL_AVAILABLE - -from .conftest import _get_client, skip_if_redis_enterprise, skip_if_server_version_lt +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 @@ -197,6 +202,10 @@ 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,