Skip to content
Browse files

Merge pull request #309 from jparise/pipeline-length

Pipelines now have a __len__() method.
  • Loading branch information...
2 parents 395ca0e + 5827683 commit 35c474b0527680650c504dde8c08f58e3973c0c5 Andy McCurdy committed Jan 6, 2013
Showing with 19 additions and 0 deletions.
  1. +3 −0 redis/client.py
  2. +16 −0 tests/pipeline.py
View
3 redis/client.py
@@ -1624,6 +1624,9 @@ def __del__(self):
except:
pass
+ def __len__(self):
+ return len(self.command_stack)
+
def reset(self):
self.command_stack = []
self.scripts = set()
View
16 tests/pipeline.py
@@ -28,6 +28,22 @@ def test_pipeline(self):
]
)
+ def test_pipeline_length(self):
+ with self.client.pipeline() as pipe:
+ # Initially empty.
+ self.assertEquals(len(pipe), 0)
+ self.assertFalse(pipe)
+
+ # Fill 'er up!
+ pipe.set('a', 'a1').set('b', 'b1').set('c', 'c1')
+ self.assertEquals(len(pipe), 3)
+ self.assertTrue(pipe)
+
+ # Execute calls reset(), so empty once again.
+ pipe.execute()
+ self.assertEquals(len(pipe), 0)
+ self.assertFalse(pipe)
+
def test_pipeline_no_transaction(self):
with self.client.pipeline(transaction=False) as pipe:
pipe.set('a', 'a1').set('b', 'b1').set('c', 'c1')

0 comments on commit 35c474b

Please sign in to comment.
Something went wrong with that request. Please try again.