Skip to content

Commit 2c9ce37

Browse files
committed
Moved self._lock initialisation to Pool constructor (#3473)
* Moved self._lock initialisation to Pool constructor * Added test case * Codestyle fixes * Added correct annotations
1 parent 4863913 commit 2c9ce37

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

redis/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@ def __init__(
13781378
# will notice the first thread already did the work and simply
13791379
# release the lock.
13801380
self._fork_lock = threading.Lock()
1381+
self._lock = threading.Lock()
13811382
self.reset()
13821383

13831384
def __repr__(self) -> (str, str):
@@ -1395,7 +1396,6 @@ def get_protocol(self):
13951396
return self.connection_kwargs.get("protocol", None)
13961397

13971398
def reset(self) -> None:
1398-
self._lock = threading.Lock()
13991399
self._created_connections = 0
14001400
self._available_connections = []
14011401
self._in_use_connections = set()

tests/test_connection_pool.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77

88
import pytest
99
import redis
10-
from redis.connection import to_bool
11-
from redis.utils import SSL_AVAILABLE
12-
13-
from .conftest import _get_client, skip_if_redis_enterprise, skip_if_server_version_lt
10+
from redis.cache import CacheConfig
11+
from redis.connection import CacheProxyConnection, Connection, to_bool
12+
from redis.utils import HIREDIS_AVAILABLE, SSL_AVAILABLE
13+
14+
from .conftest import (
15+
_get_client,
16+
skip_if_redis_enterprise,
17+
skip_if_resp_version,
18+
skip_if_server_version_lt,
19+
)
1420
from .test_pubsub import wait_for_message
1521

1622

@@ -196,6 +202,20 @@ def test_repr_contains_db_info_unix(self):
196202
expected = "path=abc,db=0,client_name=test-client"
197203
assert expected in repr(pool)
198204

205+
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
206+
@pytest.mark.onlynoncluster
207+
@skip_if_resp_version(2)
208+
@skip_if_server_version_lt("7.4.0")
209+
def test_initialise_pool_with_cache(self, master_host):
210+
pool = redis.BlockingConnectionPool(
211+
connection_class=Connection,
212+
host=master_host[0],
213+
port=master_host[1],
214+
protocol=3,
215+
cache_config=CacheConfig(),
216+
)
217+
assert isinstance(pool.get_connection("_"), CacheProxyConnection)
218+
199219

200220
class TestConnectionPoolURLParsing:
201221
def test_hostname(self):

0 commit comments

Comments
 (0)