diff --git a/pottery/__init__.py b/pottery/__init__.py index 961ac158..dcc10031 100644 --- a/pottery/__init__.py +++ b/pottery/__init__.py @@ -14,7 +14,7 @@ __title__ = 'pottery' -__version__ = '0.49' +__version__ = '0.50' __description__, __long_description__ = ( s.strip() for s in __doc__.split(sep='\n\n', maxsplit=1) ) diff --git a/pottery/cache.py b/pottery/cache.py index e324c679..f644e9ca 100644 --- a/pottery/cache.py +++ b/pottery/cache.py @@ -11,6 +11,7 @@ import functools from redis import Redis +from redis.exceptions import WatchError from .dict import RedisDict @@ -53,10 +54,19 @@ def wrapper(*args, **kwargs): class CachedOrderedDict(collections.OrderedDict): + _RETRIES = 3 _SENTINEL = object() def __init__(self, *, redis=None, key=None, keys=tuple()): - self._cache = RedisDict(redis=redis, key=key) + for _ in range(self._RETRIES): # pragma: no cover + try: + self._cache = RedisDict(redis=redis, key=key) + except WatchError: + continue + else: + break + else: # pragma: no cover + raise self.misses = set() items, miss_count, hit_count = [], 0, 0 @@ -79,4 +89,12 @@ def __enter__(self): def __exit__(self, exc_type, exc_value, traceback): if exc_type is None: # pragma: no cover cache = {key_: self[key_] for key_ in self.misses} - self._cache.update(cache) + for _ in range(self._RETRIES): + try: + self._cache.update(cache) + except WatchError: + continue + else: + break + else: + raise