diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-12-08 16:36:17 -0800 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-12-08 16:36:17 -0800 |
commit | 9cea9e8d55485b4df80556211c3976e3042100be (patch) | |
tree | 23d363b7f187c11a34ca8a9ab0211b08ca2fd583 /redis | |
parent | 38b19cd3098f0c21510a5565dae349bd1caef6dc (diff) | |
download | redis-py-9cea9e8d55485b4df80556211c3976e3042100be.tar.gz |
Allow delay between watch errors
When a watcher error occurs (due to some key being
watched being mutated) the current behavior is to
immediately try again. To avoid the thundering herd
problem a delay is nice to provide to avoid these
situations by introducing a sleep period between these
types of failures.
Diffstat (limited to 'redis')
-rwxr-xr-x | redis/client.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/redis/client.py b/redis/client.py index 70024af..26bdbca 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3,6 +3,7 @@ from itertools import chain import datetime import sys import warnings +import time import threading import time as mod_time from redis._compat import (b, basestring, bytes, imap, iteritems, iterkeys, @@ -477,6 +478,7 @@ class StrictRedis(object): """ shard_hint = kwargs.pop('shard_hint', None) value_from_callable = kwargs.pop('value_from_callable', False) + watch_delay = kwargs.pop('watch_delay', None) with self.pipeline(True, shard_hint) as pipe: while 1: try: @@ -486,6 +488,8 @@ class StrictRedis(object): exec_value = pipe.execute() return func_value if value_from_callable else exec_value except WatchError: + if watch_delay is not None and watch_delay > 0: + time.sleep(watch_delay) continue def lock(self, name, timeout=None, sleep=0.1, blocking_timeout=None, |