Skip to content

Commit

Permalink
Check aioredis version for deprecated parameter
Browse files Browse the repository at this point in the history
Starting with aioredis 1.3.1, the loop parameter is deprecated when calling
create_redis. See aio-libs-abandoned/aioredis-py#666 and django/channels_redis#179.

When running Python 3.8+ and aioredis 1.3.1+, calls should omit the loop
parameter. Otherwise, continue to include the parameter for the older
versions that expect it.
  • Loading branch information
wmorrell authored and carltongibson committed Jun 25, 2020
1 parent f2d8f49 commit 6443a14
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion channels_redis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import random
import string
import sys
import time
import types

Expand All @@ -18,6 +19,8 @@

logger = logging.getLogger(__name__)

AIOREDIS_VERSION = tuple(map(int, aioredis.__version__.split(".")))


def _wrap_close(loop, pool):
"""
Expand Down Expand Up @@ -70,7 +73,11 @@ async def pop(self, loop=None):
"""
conns, loop = self._ensure_loop(loop)
if not conns:
conns.append(await aioredis.create_redis(**self.host, loop=loop))
if sys.version_info >= (3, 8, 0) and AIOREDIS_VERSION >= (1, 3, 1):
conn = await aioredis.create_redis(**self.host)
else:
conn = await aioredis.create_redis(**self.host, loop=loop)
conns.append(conn)
conn = conns.pop()
if conn.closed:
conn = await self.pop(loop=loop)
Expand Down

0 comments on commit 6443a14

Please sign in to comment.