Skip to content

Commit 713fa03

Browse files
committed
feat: Implemented SentinelBlockingConnectionPool.
1 parent 9607608 commit 713fa03

File tree

6 files changed

+61
-17
lines changed

6 files changed

+61
-17
lines changed

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Add SentinelBlockingConnectionPool class
12
* Move doctests (doc code examples) to main branch
23
* Update `ResponseT` type hint
34
* Allow to control the minimum SSL version

docs/connections.rst

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ SentinelConnectionPool
3535
.. autoclass:: redis.sentinel.SentinelConnectionPool
3636
:members:
3737

38+
SentinelBlockingConnectionPool
39+
======================
40+
.. autoclass:: redis.sentinel.SentinelBlockingConnectionPool
41+
:members:
42+
3843

3944
Cluster Client
4045
**************

redis/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
)
3131
from redis.sentinel import (
3232
Sentinel,
33+
SentinelBlockingConnectionPool,
3334
SentinelConnectionPool,
3435
SentinelManagedConnection,
3536
SentinelManagedSSLConnection,
@@ -77,6 +78,7 @@ def int_or_str(value):
7778
"RedisError",
7879
"ResponseError",
7980
"Sentinel",
81+
"SentinelBlockingConnectionPool",
8082
"SentinelConnectionPool",
8183
"SentinelManagedConnection",
8284
"SentinelManagedSSLConnection",

redis/asyncio/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from redis.asyncio.sentinel import (
1111
Sentinel,
12+
SentinelBlockingConnectionPool,
1213
SentinelConnectionPool,
1314
SentinelManagedConnection,
1415
SentinelManagedSSLConnection,
@@ -53,6 +54,7 @@
5354
"RedisError",
5455
"ResponseError",
5556
"Sentinel",
57+
"SentinelBlockingConnectionPool",
5658
"SentinelConnectionPool",
5759
"SentinelManagedConnection",
5860
"SentinelManagedSSLConnection",

redis/asyncio/sentinel.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from redis.asyncio.client import Redis
77
from redis.asyncio.connection import (
8+
BlockingConnectionPool,
89
Connection,
910
ConnectionPool,
1011
EncodableT,
@@ -97,14 +98,7 @@ class SentinelManagedSSLConnection(SentinelManagedConnection, SSLConnection):
9798
pass
9899

99100

100-
class SentinelConnectionPool(ConnectionPool):
101-
"""
102-
Sentinel backed connection pool.
103-
104-
If ``check_connection`` flag is set to True, SentinelManagedConnection
105-
sends a PING command right after establishing the connection.
106-
"""
107-
101+
class _SentinelConnectionPoolMixin:
108102
def __init__(self, service_name, sentinel_manager, **kwargs):
109103
kwargs["connection_class"] = kwargs.get(
110104
"connection_class",
@@ -168,6 +162,27 @@ async def rotate_slaves(self) -> AsyncIterator:
168162
raise SlaveNotFoundError(f"No slave found for {self.service_name!r}")
169163

170164

165+
class SentinelConnectionPool(_SentinelConnectionPoolMixin, ConnectionPool):
166+
"""
167+
Sentinel backed connection pool.
168+
169+
If ``check_connection`` flag is set to True, SentinelManagedConnection
170+
sends a PING command right after establishing the connection.
171+
"""
172+
173+
174+
class SentinelBlockingConnectionPool(
175+
_SentinelConnectionPoolMixin,
176+
BlockingConnectionPool,
177+
):
178+
"""
179+
Sentinel blocking connection pool.
180+
181+
If ``check_connection`` flag is set to True, SentinelManagedConnection
182+
sends a PING command right after establishing the connection.
183+
"""
184+
185+
171186
class Sentinel(AsyncSentinelCommands):
172187
"""
173188
Redis Sentinel cluster client

redis/sentinel.py

+28-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
from redis.client import Redis
66
from redis.commands import SentinelCommands
7-
from redis.connection import Connection, ConnectionPool, SSLConnection
7+
from redis.connection import (
8+
BlockingConnectionPool,
9+
Connection,
10+
ConnectionPool,
11+
SSLConnection,
12+
)
813
from redis.exceptions import ConnectionError, ReadOnlyError, ResponseError, TimeoutError
914
from redis.utils import str_if_bytes
1015

@@ -134,14 +139,7 @@ def rotate_slaves(self):
134139
raise SlaveNotFoundError(f"No slave found for {self.service_name!r}")
135140

136141

137-
class SentinelConnectionPool(ConnectionPool):
138-
"""
139-
Sentinel backed connection pool.
140-
141-
If ``check_connection`` flag is set to True, SentinelManagedConnection
142-
sends a PING command right after establishing the connection.
143-
"""
144-
142+
class _SentinelConnectionPoolMixin:
145143
def __init__(self, service_name, sentinel_manager, **kwargs):
146144
kwargs["connection_class"] = kwargs.get(
147145
"connection_class",
@@ -195,6 +193,27 @@ def rotate_slaves(self):
195193
return self.proxy.rotate_slaves()
196194

197195

196+
class SentinelConnectionPool(_SentinelConnectionPoolMixin, ConnectionPool):
197+
"""
198+
Sentinel backed connection pool.
199+
200+
If ``check_connection`` flag is set to True, SentinelManagedConnection
201+
sends a PING command right after establishing the connection.
202+
"""
203+
204+
205+
class SentinelBlockingConnectionPool(
206+
_SentinelConnectionPoolMixin,
207+
BlockingConnectionPool,
208+
):
209+
"""
210+
Sentinel blocking connection pool.
211+
212+
If ``check_connection`` flag is set to True, SentinelManagedConnection
213+
sends a PING command right after establishing the connection.
214+
"""
215+
216+
198217
class Sentinel(SentinelCommands):
199218
"""
200219
Redis Sentinel cluster client

0 commit comments

Comments
 (0)