Skip to content

Commit

Permalink
Remove duplicated omit exception code
Browse files Browse the repository at this point in the history
  • Loading branch information
jdufresne committed Apr 13, 2020
1 parent 99ebe7c commit e665a64
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions django_redis/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
if DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS:
logger = logging.getLogger(DJANGO_REDIS_LOGGER or __name__)

CONNECTION_INTERRUPTED = object()


def omit_exception(method=None, return_value=None):
"""
Expand Down Expand Up @@ -83,16 +85,15 @@ def incr_version(self, *args, **kwargs):
def add(self, *args, **kwargs):
return self.client.add(*args, **kwargs)

@omit_exception
def get(self, key, default=None, version=None, client=None):
try:
return self.client.get(key, default=default, version=version, client=client)
except ConnectionInterrupted as e:
if self._ignore_exceptions:
if DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS:
logger.error(str(e))
return default
raise
value = self._get(key, default, version, client)
if value is CONNECTION_INTERRUPTED:
value = default
return value

@omit_exception(return_value=CONNECTION_INTERRUPTED)
def _get(self, key, default, version, client):
return self.client.get(key, default=default, version=version, client=client)

@omit_exception
def delete(self, *args, **kwargs):
Expand Down

0 comments on commit e665a64

Please sign in to comment.