Skip to content

Commit

Permalink
properly update inc/dec functions
Browse files Browse the repository at this point in the history
  • Loading branch information
drcpu-github committed Jul 22, 2023
1 parent 543cbd5 commit 8141bfb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/cachelib/memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,20 @@ def clear(self) -> bool:

def inc(self, key: str, delta: int = 1) -> _t.Optional[int]:
key = self._normalize_key(key)
value = (self._client.get(key) or 0) + delta
if self.pylibmc_used:
with self._client.reserve(block=self.blocking) as mc:
value = (mc.get(key) or 0) + delta
else:
value = (self._client.get(key) or 0) + delta
return value if self.set(key, value) else None

def dec(self, key: str, delta: int = 1) -> _t.Optional[int]:
key = self._normalize_key(key)
value = (self._client.get(key) or 0) - delta
if self.pylibmc_used:
with self._client.reserve(block=self.blocking) as mc:
value = (mc.get(key) or 0) - delta
else:
value = (self._client.get(key) or 0) - delta
return value if self.set(key, value) else None

def import_preferred_memcache_lib(self, servers: _t.Any, threads: int) -> _t.Any:
Expand Down

0 comments on commit 8141bfb

Please sign in to comment.