@@ -278,6 +278,17 @@ def __init__(
278
278
single_connection_client:
279
279
if `True`, connection pool is not used. In that case `Redis`
280
280
instance use is not thread safe.
281
+ decode_responses:
282
+ if `True`, the response will be decoded to utf-8.
283
+ Argument is ignored when connection_pool is provided.
284
+ maint_notifications_config:
285
+ configuration the pool to support maintenance notifications - see
286
+ `redis.maint_notifications.MaintNotificationsConfig` for details.
287
+ Only supported with RESP3
288
+ If not provided and protocol is RESP3, the maintenance notifications
289
+ will be enabled by default (logic is included in the connection pool
290
+ initialization).
291
+ Argument is ignored when connection_pool is provided.
281
292
"""
282
293
if event_dispatcher is None :
283
294
self ._event_dispatcher = EventDispatcher ()
@@ -354,6 +365,22 @@ def __init__(
354
365
"cache_config" : cache_config ,
355
366
}
356
367
)
368
+ maint_notifications_enabled = (
369
+ maint_notifications_config and maint_notifications_config .enabled
370
+ )
371
+ if maint_notifications_enabled and protocol not in [
372
+ 3 ,
373
+ "3" ,
374
+ ]:
375
+ raise RedisError (
376
+ "Maintenance notifications handlers on connection are only supported with RESP version 3"
377
+ )
378
+ if maint_notifications_config :
379
+ kwargs .update (
380
+ {
381
+ "maint_notifications_config" : maint_notifications_config ,
382
+ }
383
+ )
357
384
connection_pool = ConnectionPool (** kwargs )
358
385
self ._event_dispatcher .dispatch (
359
386
AfterPooledConnectionsInstantiationEvent (
@@ -377,23 +404,6 @@ def __init__(
377
404
]:
378
405
raise RedisError ("Client caching is only supported with RESP version 3" )
379
406
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
-
397
407
self .single_connection_lock = threading .RLock ()
398
408
self .connection = None
399
409
self ._single_connection_client = single_connection_client
@@ -591,15 +601,9 @@ def monitor(self):
591
601
return Monitor (self .connection_pool )
592
602
593
603
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
- )
599
604
return self .__class__ (
600
605
connection_pool = self .connection_pool ,
601
606
single_connection_client = True ,
602
- maint_notifications_config = maint_notifications_config ,
603
607
)
604
608
605
609
def __enter__ (self ):
0 commit comments