diff --git a/README.md b/README.md index 4c63e82..50c77f2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A Redis client for Python supporting many Redis features and Python synchronous - Transparent API (Just call the Redis commands, and the library will figure out cluster routing, script caching, etc...) - Per context and command properties (database #, decoding, RESP3 attributes) -- Asynchronous I/O support with the same exact API (but with the await keyword), targeting asyncio, trio and curio (using [AnyIO](https://github.com/agronholm/anyio) which needs to be installed as well if you want async I/O) +- Asynchronous I/O support with the same exact API (but with the await keyword), targeting asyncio and trio (using [AnyIO](https://github.com/agronholm/anyio) which needs to be installed as well if you want async I/O) - Modular API allowing for easy support for multiple synchronous and asynchronous event loops and disabling of unneeded features - CI Testing for CPython 3.5, 3.6, 3.7, 3.8, 3.9 and PyPy3 with Redis 5 and Redis 6 - No legacy support for old language features diff --git a/justredis/nonsync/connectionpool.py b/justredis/nonsync/connectionpool.py index fa22545..da7b439 100644 --- a/justredis/nonsync/connectionpool.py +++ b/justredis/nonsync/connectionpool.py @@ -51,7 +51,7 @@ async def take(self): if not conn.closed(): break if self._limit is not None: - await self._limit.release() + self._limit.release() except IndexError: if self._limit is not None and not await self._limit.acquire(self._wait_timeout): raise ConnectionPoolError("Could not acquire an connection form the pool") @@ -59,13 +59,13 @@ async def take(self): conn = await Connection.create(**self._connection_settings) except Exception: if self._limit is not None: - await self._limit.release() + self._limit.release() raise self._connections_in_use.add(conn) return conn async def release(self, conn): - async with self._shield(): + with self._shield(): async with self._lock: try: self._connections_in_use.remove(conn) @@ -77,7 +77,7 @@ async def release(self, conn): if not conn.closed(): self._connections_available.append(conn) elif self._limit is not None: - await self._limit.release() + self._limit.release() async def __call__(self, *cmd, **kwargs): if not cmd: diff --git a/justredis/nonsync/environments/anyio.py b/justredis/nonsync/environments/anyio.py index e011a97..159ad79 100644 --- a/justredis/nonsync/environments/anyio.py +++ b/justredis/nonsync/environments/anyio.py @@ -1,9 +1,9 @@ import anyio try: - anyio.create_tcp_listener + anyio.Lock except AttributeError: - raise AttributeError("You are using an old and incompatible AnyIO version, the minimum required version is AnyIO 2.0.0 .") + raise AttributeError("You are using an old and incompatible AnyIO version, the minimum required version is AnyIO 3.0.0 .") import socket import sys import ssl @@ -21,7 +21,7 @@ async def tcpsocket(address=None, connect_timeout=None, tcp_keepalive=None, tcp_nodelay=None, **kwargs): if address is None: address = ("localhost", 6379) - async with anyio.fail_after(connect_timeout): + with anyio.fail_after(connect_timeout): sock = await anyio.connect_tcp(address[0], address[1]) if tcp_nodelay is not None: if tcp_nodelay: @@ -44,7 +44,7 @@ async def tcpsocket(address=None, connect_timeout=None, tcp_keepalive=None, tcp_ async def unixsocket(address=None, connect_timeout=None, **kwargs): if address is None: address = "/tmp/redis.sock" - async with anyio.fail_after(connect_timeout): + with anyio.fail_after(connect_timeout): sock = await anyio.connect_unix(address) return sock @@ -85,7 +85,7 @@ async def aclose(self, force=False): async def send(self, data): if self._socket_timeout: - async with anyio.fail_after(self._socket_timeout): + with anyio.fail_after(self._socket_timeout): await self._socket.send(data) else: await self._socket.send(data) @@ -96,7 +96,7 @@ async def recv(self, timeout=False): timeout = self._socket_timeout if timeout: try: - async with anyio.fail_after(timeout): + with anyio.fail_after(timeout): return await self._socket.receive(self._buffersize) except TimeoutError: return None @@ -112,14 +112,14 @@ def peername(self): class OurSemaphore: def __init__(self, value): - self._semaphore = anyio.create_capcity_limiter(value) + self._semaphore = anyio.CapacityLimiter(value) - async def release(self): - await self._semaphore.release() + def release(self): + self._semaphore.release() async def acquire(self, timeout=None): if timeout: - async with anyio.fail_after(timeout): + with anyio.fail_after(timeout): await self._semaphore.acquire() else: await self._semaphore.acquire() @@ -144,12 +144,12 @@ def semaphore(limit): @staticmethod def lock(): - return anyio.create_lock() + return anyio.Lock() # async only? @staticmethod def shield(): - return anyio.open_cancel_scope(shield=True) + return anyio.CancelScope(shield=True) # async only? @staticmethod diff --git a/setup.cfg b/setup.cfg index 4a7a8ee..61c7d95 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = justredis -version = 0.0.1a3 +version = 0.0.1a4 description = A Redis client for Python supporting many Redis features and Python synchronous (Python 3.5+) and asynchronous (Python 3.6+) communication. long_description = file: README.md long_description_content_type = text/markdown diff --git a/tests/async/test_async.py b/tests/async/test_async.py index 484a302..b2f9726 100644 --- a/tests/async/test_async.py +++ b/tests/async/test_async.py @@ -247,10 +247,10 @@ async def test_cancel(client): r = client async with anyio.create_task_group() as tg: - await tg.spawn(r, "blpop", "a", 20) + tg.start_soon(r, "blpop", "a", 20) await anyio.sleep(1) - await tg.cancel_scope.cancel() + tg.cancel_scope.cancel() await anyio.sleep(1) async with anyio.create_task_group() as tg: - await tg.spawn(r, "blpop", "a", 1) + tg.start_soon(r, "blpop", "a", 1) diff --git a/tox.ini b/tox.ini index b6f4611..fad8cb5 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ skip_missing_interpreters = true deps = pytest pytest-cov - py{36,37,38,39,py3}: anyio[trio,curio] + py{36,37,38,39,py3}: anyio[trio] commands = py{35,36,37,38,39,py3}: pytest --cov={toxinidir}/justredis --cov={toxinidir}/tests --cov-append --cov-report=term-missing {posargs} passenv =