From 24b9369c4afc23c827c8f4e4e71d70fee52e0481 Mon Sep 17 00:00:00 2001 From: "larry.liu" Date: Wed, 19 Jul 2017 22:59:49 +0800 Subject: [PATCH] redis pub/sub support set password At first I added it to URL, but it was not easy to handle when the password value was None, so I added a parameter "password" --- socketio/asyncio_redis_manager.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/socketio/asyncio_redis_manager.py b/socketio/asyncio_redis_manager.py index 7341033..826c49c 100644 --- a/socketio/asyncio_redis_manager.py +++ b/socketio/asyncio_redis_manager.py @@ -53,7 +53,7 @@ class AsyncRedisManager(AsyncPubSubManager): # pragma: no cover name = 'aioredis' def __init__(self, url='redis://localhost:6379/0', channel='socketio', - write_only=False): + write_only=False, password=None): if aioredis is None: raise RuntimeError('Redis package is not installed ' '(Run "pip install aioredis" in your ' @@ -61,18 +61,19 @@ class AsyncRedisManager(AsyncPubSubManager): # pragma: no cover self.host, self.port, self.db = _parse_redis_url(url) self.pub = None self.sub = None + self.password = password super().__init__(channel=channel, write_only=write_only) async def _publish(self, data): if self.pub is None: self.pub = await aioredis.create_redis((self.host, self.port), - db=self.db) + db=self.db, password=self.password) return await self.pub.publish(self.channel, pickle.dumps(data)) async def _listen(self): if self.sub is None: self.sub = await aioredis.create_redis((self.host, self.port), - db=self.db) + db=self.db, password=self.password) self.ch = (await self.sub.subscribe(self.channel))[0] while True: return await self.ch.get()