Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 0eda142

Browse files
committed
Wrap redis calls in try..except blocks in lru module
1 parent 458907c commit 0eda142

File tree

1 file changed

+19
-4
lines changed
  • depends/docker-registry-core/docker_registry/core

1 file changed

+19
-4
lines changed

depends/docker-registry-core/docker_registry/core/lru.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ def wrapper(*args):
6565
content = args[-1]
6666
key = args[-2]
6767
key = cache_key(key)
68-
redis_conn.set(key, content)
68+
try:
69+
redis_conn.set(key, content)
70+
except redis.exceptions.ConnectionError:
71+
logging.warning("LRU: Redis connection error")
72+
6973
return f(*args)
7074
if redis_conn is None:
7175
return f
@@ -77,13 +81,21 @@ def get(f):
7781
def wrapper(*args):
7882
key = args[-1]
7983
key = cache_key(key)
80-
content = redis_conn.get(key)
84+
try:
85+
content = redis_conn.get(key)
86+
except redis.exceptions.ConnectionError:
87+
logging.warning("LRU: Redis connection error")
88+
content = None
89+
8190
if content is not None:
8291
return content
8392
# Refresh cache
8493
content = f(*args)
8594
if content is not None:
86-
redis_conn.set(key, content)
95+
try:
96+
redis_conn.set(key, content)
97+
except redis.exceptions.ConnectionError:
98+
logging.warning("LRU: Redis connection error")
8799
return content
88100
if redis_conn is None:
89101
return f
@@ -95,7 +107,10 @@ def remove(f):
95107
def wrapper(*args):
96108
key = args[-1]
97109
key = cache_key(key)
98-
redis_conn.delete(key)
110+
try:
111+
redis_conn.delete(key)
112+
except redis.exceptions.ConnectionError:
113+
logging.warning("LRU: Redis connection error")
99114
return f(*args)
100115
if redis_conn is None:
101116
return f

0 commit comments

Comments
 (0)