Skip to content

Commit

Permalink
Fix handling of FakePipeline.execute when no commands queued
Browse files Browse the repository at this point in the history
Closes #217.
  • Loading branch information
bmerry committed Sep 20, 2018
1 parent 6b9c43d commit 1fbc29c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,8 @@ def __len__(self):

def execute(self, raise_on_error=True):
"""Run all the commands in the pipeline and return the results."""
if not self.commands:
return []
try:
if self.watching:
mismatches = [
Expand Down
9 changes: 9 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2848,6 +2848,15 @@ def test_pipeline_length(self):
p.set('baz', 'quux').get('baz')
self.assertEqual(2, len(p))

def test_pipeline_no_commands(self):
# redis-py's execute is a nop if there are no commands queued,
# so it succeeds even if watched keys have been changed.
self.redis.set('foo', '1')
p = self.redis.pipeline()
p.watch('foo')
self.redis.set('foo', '2')
self.assertEqual(p.execute(), [])

def test_key_patterns(self):
self.redis.mset({'one': 1, 'two': 2, 'three': 3, 'four': 4})
self.assertItemsEqual(self.redis.keys('*o*'),
Expand Down

0 comments on commit 1fbc29c

Please sign in to comment.