From 42567f3167d636d980c654994a27808826d5103d Mon Sep 17 00:00:00 2001 From: elbaro Date: Tue, 7 Jan 2025 18:39:57 +0900 Subject: [PATCH 1/3] Update commands_test.py --- tests/commands_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/commands_test.py b/tests/commands_test.py index ae5768e..e88f74a 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] + value = await mcache.incr(b'not:' + key, 5) + assert value 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] + value = await mcache.decr(b'not:' + key, 6) + assert value is None + async def test_stats(mcache: Client) -> None: stats = await mcache.stats() From b2ffce7020a950a5918a0c22fa7ee852785a50e6 Mon Sep 17 00:00:00 2001 From: elbaro Date: Tue, 7 Jan 2025 18:41:54 +0900 Subject: [PATCH 2/3] Fix _incr_decr --- aiomcache/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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]: From b124daa9d1ccc0005be53f5090453c422a466c4b Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Tue, 7 Jan 2025 11:23:39 +0000 Subject: [PATCH 3/3] Apply suggestions from code review --- tests/commands_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/commands_test.py b/tests/commands_test.py index e88f74a..32994cb 100644 --- a/tests/commands_test.py +++ b/tests/commands_test.py @@ -299,8 +299,8 @@ async def test_incr_errors(mcache: Client) -> None: with pytest.raises(ClientException): await mcache.incr(key, 3.14) # type: ignore[arg-type] - value = await mcache.incr(b'not:' + key, 5) - assert value is None + ivalue = await mcache.incr(b'not:' + key, 5) + assert ivalue is None async def test_decr(mcache: Client) -> None: @@ -327,8 +327,8 @@ async def test_decr_errors(mcache: Client) -> None: with pytest.raises(ClientException): await mcache.decr(key, 3.14) # type: ignore[arg-type] - value = await mcache.decr(b'not:' + key, 6) - assert value is None + ivalue = await mcache.decr(b'not:' + key, 6) + assert ivalue is None async def test_stats(mcache: Client) -> None: