Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Pipelines now have a __len__() method. #309

Merged
merged 1 commit into from Jan 7, 2013
Jump to file or symbol
Failed to load files and symbols.
+19 −0
Split
View
@@ -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
@@ -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')