@@ -260,18 +260,6 @@ async def flush(self):
260
260
await shard .flush ()
261
261
262
262
263
- def on_close_noop (sender , exc = None ):
264
- """
265
- If you don't pass an `on_close` function to the `Receiver`, then it
266
- defaults to one that closes the Receiver whenever the last subscriber
267
- unsubscribes. That is not what we want; instead, we want the Receiver
268
- to continue even if no one is subscribed, because soon someone *will*
269
- subscribe and we want things to continue from there. Passing this
270
- empty function solves it.
271
- """
272
- pass
273
-
274
-
275
263
class RedisSingleShardConnection :
276
264
def __init__ (self , host , channel_layer ):
277
265
self .host = host .copy () if type (host ) is dict else {"address" : host }
@@ -427,26 +415,20 @@ def _notify_consumers(self, mtype):
427
415
async def _ensure_redis (self ):
428
416
if self ._redis is None :
429
417
if self .master_name is None :
430
- self ._redis = aioredis .Redis (
431
- connection_pool = aioredis .ConnectionPool .from_url (
432
- self .host ["address" ]
433
- )
434
- )
418
+ pool = aioredis .ConnectionPool .from_url (self .host ["address" ])
435
419
else :
436
420
# aioredis default timeout is way too low
437
- self ._redis = aioredis .sentinel .Sentinel (
438
- self .host ["sentinels" ], socket_timeout = 2
421
+ pool = aioredis .sentinel .SentinelConnectionPool (
422
+ self .master_name ,
423
+ aioredis .sentinel .Sentinel (
424
+ self .host ["sentinels" ], socket_timeout = 2
425
+ ),
439
426
)
440
-
441
- def _get_aioredis_pool (self ):
442
- if self .master_name is None :
443
- return self ._redis .connection_pool
444
- else :
445
- return self ._redis .master_for (self .master_name ).connection_pool
427
+ self ._redis = aioredis .Redis (connection_pool = pool )
446
428
447
429
async def _get_redis_conn (self ):
448
430
await self ._ensure_redis ()
449
- return aioredis . Redis ( connection_pool = self ._get_aioredis_pool ())
431
+ return self ._redis
450
432
451
433
async def _put_redis_conn (self , conn ):
452
434
if conn :
0 commit comments