Skip to content

Commit 1a68689

Browse files
authored
Merge branch 'master' into ps_fix_evalsha_typehints
2 parents f291329 + d0e92c6 commit 1a68689

File tree

8 files changed

+1782
-1399
lines changed

8 files changed

+1782
-1399
lines changed

redis/client.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
from redis.lock import Lock
5959
from redis.maint_notifications import (
6060
MaintNotificationsConfig,
61-
MaintNotificationsPoolHandler,
6261
)
6362
from redis.retry import Retry
6463
from redis.utils import (
@@ -278,6 +277,17 @@ def __init__(
278277
single_connection_client:
279278
if `True`, connection pool is not used. In that case `Redis`
280279
instance use is not thread safe.
280+
decode_responses:
281+
if `True`, the response will be decoded to utf-8.
282+
Argument is ignored when connection_pool is provided.
283+
maint_notifications_config:
284+
configuration the pool to support maintenance notifications - see
285+
`redis.maint_notifications.MaintNotificationsConfig` for details.
286+
Only supported with RESP3
287+
If not provided and protocol is RESP3, the maintenance notifications
288+
will be enabled by default (logic is included in the connection pool
289+
initialization).
290+
Argument is ignored when connection_pool is provided.
281291
"""
282292
if event_dispatcher is None:
283293
self._event_dispatcher = EventDispatcher()
@@ -354,6 +364,22 @@ def __init__(
354364
"cache_config": cache_config,
355365
}
356366
)
367+
maint_notifications_enabled = (
368+
maint_notifications_config and maint_notifications_config.enabled
369+
)
370+
if maint_notifications_enabled and protocol not in [
371+
3,
372+
"3",
373+
]:
374+
raise RedisError(
375+
"Maintenance notifications handlers on connection are only supported with RESP version 3"
376+
)
377+
if maint_notifications_config:
378+
kwargs.update(
379+
{
380+
"maint_notifications_config": maint_notifications_config,
381+
}
382+
)
357383
connection_pool = ConnectionPool(**kwargs)
358384
self._event_dispatcher.dispatch(
359385
AfterPooledConnectionsInstantiationEvent(
@@ -377,23 +403,6 @@ def __init__(
377403
]:
378404
raise RedisError("Client caching is only supported with RESP version 3")
379405

380-
if maint_notifications_config and self.connection_pool.get_protocol() not in [
381-
3,
382-
"3",
383-
]:
384-
raise RedisError(
385-
"Push handlers on connection are only supported with RESP version 3"
386-
)
387-
if maint_notifications_config and maint_notifications_config.enabled:
388-
self.maint_notifications_pool_handler = MaintNotificationsPoolHandler(
389-
self.connection_pool, maint_notifications_config
390-
)
391-
self.connection_pool.set_maint_notifications_pool_handler(
392-
self.maint_notifications_pool_handler
393-
)
394-
else:
395-
self.maint_notifications_pool_handler = None
396-
397406
self.single_connection_lock = threading.RLock()
398407
self.connection = None
399408
self._single_connection_client = single_connection_client
@@ -591,15 +600,9 @@ def monitor(self):
591600
return Monitor(self.connection_pool)
592601

593602
def client(self):
594-
maint_notifications_config = (
595-
None
596-
if self.maint_notifications_pool_handler is None
597-
else self.maint_notifications_pool_handler.config
598-
)
599603
return self.__class__(
600604
connection_pool=self.connection_pool,
601605
single_connection_client=True,
602-
maint_notifications_config=maint_notifications_config,
603606
)
604607

605608
def __enter__(self):

redis/cluster.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
WatchError,
5151
)
5252
from redis.lock import Lock
53+
from redis.maint_notifications import MaintNotificationsConfig
5354
from redis.retry import Retry
5455
from redis.utils import (
5556
deprecated_args,
@@ -1663,6 +1664,11 @@ def create_redis_node(self, host, port, **kwargs):
16631664
backoff=NoBackoff(), retries=0, supported_errors=(ConnectionError,)
16641665
)
16651666

1667+
protocol = kwargs.get("protocol", None)
1668+
if protocol in [3, "3"]:
1669+
kwargs.update(
1670+
{"maint_notifications_config": MaintNotificationsConfig(enabled=False)}
1671+
)
16661672
if self.from_url:
16671673
# Create a redis node with a costumed connection pool
16681674
kwargs.update({"host": host})

0 commit comments

Comments
 (0)