From ea813d77de814e5f80806cd3f41f15220991f624 Mon Sep 17 00:00:00 2001 From: Pieter Ennes Date: Tue, 26 Jun 2018 10:54:09 +0100 Subject: [PATCH] Align bool/len behaviour of pipeline. --- fakeredis.py | 3 +++ test_fakeredis.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/fakeredis.py b/fakeredis.py index 1472f46..e36deb8 100644 --- a/fakeredis.py +++ b/fakeredis.py @@ -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: diff --git a/test_fakeredis.py b/test_fakeredis.py index f08527b..02d1026 100644 --- a/test_fakeredis.py +++ b/test_fakeredis.py @@ -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*'),