5858from redis .lock import Lock
5959from redis .maint_notifications import (
6060 MaintNotificationsConfig ,
61- MaintNotificationsPoolHandler ,
6261)
6362from redis .retry import Retry
6463from 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 ):
0 commit comments