Skip to content

Commit 1ffc28e

Browse files
chayimbarshaul
authored andcommitted
Pipeline DISCARD support (redis#1565)
closes redis#1539 Part of redis#1546 (cherry picked from commit febede1) cr: https://code.amazon.com/reviews/CR-57987360
1 parent 52e1896 commit 1ffc28e

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

tests/test_pipeline.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import pytest
22

33
import redis
4-
from .conftest import wait_for_command, skip_if_cluster_mode
4+
from .conftest import wait_for_command, skip_if_server_version_lt, skip_if_cluster_mode
55

66

7-
@skip_if_cluster_mode()
87
class TestPipeline:
98
def test_pipeline_is_true(self, r):
109
"Ensure pipeline instances are not false-y"
@@ -354,3 +353,29 @@ def test_pipeline_with_bitfield(self, r):
354353

355354
assert pipe == pipe2
356355
assert response == [True, [0, 0, 15, 15, 14], b'1']
356+
357+
@skip_if_server_version_lt('2.0.0')
358+
def test_pipeline_discard(self, r):
359+
360+
# empty pipeline should raise an error
361+
with r.pipeline() as pipe:
362+
pipe.set('key', 'someval')
363+
pipe.discard()
364+
with pytest.raises(redis.exceptions.ResponseError):
365+
pipe.execute()
366+
367+
# setting a pipeline and discarding should do the same
368+
with r.pipeline() as pipe:
369+
pipe.set('key', 'someval')
370+
pipe.set('someotherkey', 'val')
371+
response = pipe.execute()
372+
pipe.set('key', 'another value!')
373+
pipe.discard()
374+
pipe.set('key', 'another vae!')
375+
with pytest.raises(redis.exceptions.ResponseError):
376+
pipe.execute()
377+
378+
pipe.set('foo', 'bar')
379+
response = pipe.execute()
380+
assert response[0]
381+
assert r.get('foo') == b'bar'

0 commit comments

Comments
 (0)