Skip to content

Commit

Permalink
Merge pull request #195 from skion/fix-pipeline-len
Browse files Browse the repository at this point in the history
Align bool/len behaviour of pipeline
  • Loading branch information
bmerry authored Jun 26, 2018
2 parents 1e43347 + ea813d7 commit 5bd2f1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,9 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
self.reset()

def __len__(self):
return len(self.commands)

def execute(self, raise_on_error=True):
"""Run all the commands in the pipeline and return the results."""
try:
Expand Down
9 changes: 9 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,15 @@ def callback(pipe):

self.assertEqual('OUR-RETURN-VALUE', res)

def test_pipeline_empty(self):
p = self.redis.pipeline()
self.assertFalse(p)

def test_pipeline_length(self):
p = self.redis.pipeline()
p.set('baz', 'quux').get('baz')
self.assertEqual(2, len(p))

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 5bd2f1b

Please sign in to comment.