Refs #33061 -- Removed unnecessary BaseMemcachedCache.decr().

This commit is contained in:
Mariusz Felisiak 2021-08-31 10:37:59 +02:00 committed by GitHub
parent 2c912c3488
commit 93e06f2978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 23 deletions

View File

@ -105,33 +105,17 @@ class BaseMemcachedCache(BaseCache):
self._cache.disconnect_all() self._cache.disconnect_all()
def incr(self, key, delta=1, version=None): def incr(self, key, delta=1, version=None):
# memcached doesn't support a negative delta
if delta < 0:
return self.decr(key, -delta, version=version)
key = self.make_key(key, version=version) key = self.make_key(key, version=version)
self.validate_key(key) self.validate_key(key)
try: try:
# Memcached doesn't support negative delta.
if delta < 0:
val = self._cache.decr(key, -delta)
else:
val = self._cache.incr(key, delta) val = self._cache.incr(key, delta)
# Normalize an exception raised by the underlying client library to # Normalize an exception raised by the underlying client library to
# ValueError in the event of a nonexistent key when calling incr(). # ValueError in the event of a nonexistent key when calling
except self.LibraryValueNotFoundException: # incr()/decr().
val = None
if val is None:
raise ValueError("Key '%s' not found" % key)
return val
def decr(self, key, delta=1, version=None):
# memcached doesn't support a negative delta
if delta < 0:
return self.incr(key, -delta, version=version)
key = self.make_key(key, version=version)
self.validate_key(key)
try:
val = self._cache.decr(key, delta)
# Normalize an exception raised by the underlying client library to
# ValueError in the event of a nonexistent key when calling decr().
except self.LibraryValueNotFoundException: except self.LibraryValueNotFoundException:
val = None val = None
if val is None: if val is None: