|
1 | 1 | import pytest
|
2 | 2 |
|
3 | 3 | 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 |
5 | 5 |
|
6 | 6 |
|
7 |
| -@skip_if_cluster_mode() |
8 | 7 | class TestPipeline:
|
9 | 8 | def test_pipeline_is_true(self, r):
|
10 | 9 | "Ensure pipeline instances are not false-y"
|
@@ -354,3 +353,29 @@ def test_pipeline_with_bitfield(self, r):
|
354 | 353 |
|
355 | 354 | assert pipe == pipe2
|
356 | 355 | 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