diff options
| author | Brian Maissy <brian@medigate.io> | 2019-10-24 09:29:00 +0300 |
|---|---|---|
| committer | Andy McCurdy <andy@andymccurdy.com> | 2019-10-24 00:06:11 -0700 |
| commit | c1415c296be56ec14fa29aaa2af04eb1c8278f77 (patch) | |
| tree | 9cb9adddb1404c7d8418902da04f715e4b690156 | |
| parent | fa0b0392c86126cae1a264197dddab647fa37821 (diff) | |
| download | redis-py-c1415c296be56ec14fa29aaa2af04eb1c8278f77.tar.gz | |
Allow Pipeline.execute() to execute on empty command stack if it is watching keys
| -rw-r--r-- | CHANGES | 7 | ||||
| -rwxr-xr-x | redis/client.py | 2 | ||||
| -rw-r--r-- | tests/test_pipeline.py | 13 |
3 files changed, 20 insertions, 2 deletions
@@ -1,9 +1,14 @@ +* (IN DEVELOPMENT) + * Allow empty pipelines to be executed if there are WATCHed keys. + This is a convenient way to test if any of the watched keys changed + without actually running any other commands. Thanks @brianmaissy. + #1233, #1234 * 3.3.11 * Further fix for the SSLError -> TimeoutError mapping to work on obscure releases of Python 2.7. * 3.3.10 * Fixed a potential error handling bug for the SSLError -> TimeoutError - mapping introduced in 3.3.9. hanks @zbristow. #1224 + mapping introduced in 3.3.9. Thanks @zbristow. #1224 * 3.3.9 * Mapped Python 2.7 SSLError to TimeoutError where appropriate. Timeouts should now consistently raise TimeoutErrors on Python 2.7 for both diff --git a/redis/client.py b/redis/client.py index df1ebfd..1e5ca02 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3670,7 +3670,7 @@ class Pipeline(Redis): def execute(self, raise_on_error=True): "Execute all the commands in the current pipeline" stack = self.command_stack - if not stack: + if not stack and not self.watching: return [] if self.scripts: self.load_scripts() diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 2e2507a..264a64f 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -191,6 +191,19 @@ class TestPipeline(object): assert not pipe.watching + def test_watch_failure_in_empty_transaction(self, r): + r['a'] = 1 + r['b'] = 2 + + with r.pipeline() as pipe: + pipe.watch('a', 'b') + r['b'] = 3 + pipe.multi() + with pytest.raises(redis.WatchError): + pipe.execute() + + assert not pipe.watching + def test_unwatch(self, r): r['a'] = 1 r['b'] = 2 |
