Skip to content

Commit

Permalink
Merge pull request redis#567 from harlowja/watch-delay
Browse files Browse the repository at this point in the history
Allow delay between watch errors
  • Loading branch information
andymccurdy committed Dec 9, 2014
2 parents 38b19cd + 9cea9e8 commit 54e1040
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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,
Expand Down Expand Up @@ -477,6 +478,7 @@ def transaction(self, func, *watches, **kwargs):
"""
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:
Expand All @@ -486,6 +488,8 @@ def transaction(self, func, *watches, **kwargs):
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,
Expand Down

0 comments on commit 54e1040

Please sign in to comment.