Skip to content

Commit dc602b5

Browse files
committed
Remove some unnecessary code
1 parent 101aa08 commit dc602b5

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

channels_redis/pubsub.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,6 @@ async def flush(self):
260260
await shard.flush()
261261

262262

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-
275263
class RedisSingleShardConnection:
276264
def __init__(self, host, channel_layer):
277265
self.host = host.copy() if type(host) is dict else {"address": host}
@@ -427,26 +415,20 @@ def _notify_consumers(self, mtype):
427415
async def _ensure_redis(self):
428416
if self._redis is None:
429417
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"])
435419
else:
436420
# 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+
),
439426
)
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)
446428

447429
async def _get_redis_conn(self):
448430
await self._ensure_redis()
449-
return aioredis.Redis(connection_pool=self._get_aioredis_pool())
431+
return self._redis
450432

451433
async def _put_redis_conn(self, conn):
452434
if conn:

0 commit comments

Comments
 (0)