Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions aiomcache/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
6 changes: 6 additions & 0 deletions tests/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand Down