Hi,

Did you ever work out how to do this?

The only way I could work out how to use a shared pool was to go back to 
the regular sync `redis` library and use sync_to_async, for example

`settings.py`

REDIS_PRO_POOL = redis.ConnectionPool(host='localhost', port=6379, db=3)


`consumer.py`

class TestConsumer(AsyncWebsocketConsumer):

    @sync_to_async
    def test(self, value):
        r = redis.Redis(connection_pool=settings.REDIS_PRO_POOL)
        r.set("TEST", value)
        print(r.get(value))
        r.close()

    async def connect(self):
        await self.test("hello")   
        ....





On Tuesday, May 14, 2019 at 3:57:30 AM UTC+1, CrazyNPC wrote:
>
> Hello,
> Now I create new connection in connect event every time, code like this
> async def connect(self):
>     self.redis = await aioredis.create_redis(
>             'redis://localhost',encoding='utf-8')
> async def disconnect(self, close_code):
>      await self.redis.close()
>
> I need something like  self.channel_layer ,using pool connection across 
> every consumer.
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/44aafbcc-dc47-4de3-ae39-70c38e3b3e2c%40googlegroups.com.

Reply via email to