diff --git a/aiomcache/client.py b/aiomcache/client.py index 78896f4..eeba3f4 100644 --- a/aiomcache/client.py +++ b/aiomcache/client.py @@ -410,10 +410,12 @@ async def _incr_decr( ) -> Optional[int]: cmd = b"%b %b %a\r\n" % (command, key, delta) resp = await self._execute_simple_command(conn, cmd) - if not resp.isdigit() or resp == const.NOT_FOUND: + if resp == const.NOT_FOUND: + return None + if not resp.isdigit(): raise ClientException( 'Memcached {} command failed'.format(str(command)), resp) - return int(resp) if resp.isdigit() else None + return int(resp) @acquire async def incr(self, conn: Connection, key: bytes, increment: int = 1) -> Optional[int]: diff --git a/tests/commands_test.py b/tests/commands_test.py index ae5768e..32994cb 100644 --- a/tests/commands_test.py +++ b/tests/commands_test.py @@ -299,6 +299,9 @@ async def test_incr_errors(mcache: Client) -> None: with pytest.raises(ClientException): await mcache.incr(key, 3.14) # type: ignore[arg-type] + ivalue = await mcache.incr(b'not:' + key, 5) + assert ivalue is None + async def test_decr(mcache: Client) -> None: key, value = b'key:decr:1', b'17' @@ -324,6 +327,9 @@ async def test_decr_errors(mcache: Client) -> None: with pytest.raises(ClientException): await mcache.decr(key, 3.14) # type: ignore[arg-type] + ivalue = await mcache.decr(b'not:' + key, 6) + assert ivalue is None + async def test_stats(mcache: Client) -> None: stats = await mcache.stats()