diff --git a/redis/client.py b/redis/client.py index 1560c96afd..163968b673 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3874,7 +3874,7 @@ def __enter__(self): return self def __exit__(self, exc_type, exc_value, traceback): - self.reset() + self.execute() # also resets def __del__(self): try: diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 9bc4a9f4d9..727068b51d 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -51,6 +51,15 @@ def test_pipeline_length(self, r): pipe.execute() assert len(pipe) == 0 + def test_pipeline_autoexecute(self, r): + with r.pipeline() as pipe: + # Fill 'er up! + pipe.set('d', 'd1').set('e', 'e1').set('f', 'f1') + assert len(pipe) == 3 + + # exiting with block calls execute() and reset(), so empty once again + assert len(pipe) == 0 + def test_pipeline_no_transaction(self, r): with r.pipeline(transaction=False) as pipe: pipe.set('a', 'a1').set('b', 'b1').set('c', 'c1')