Skip to content

Commit

Permalink
Allow transaction=False argument to FakeRedis.pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
pdc committed Apr 7, 2012
1 parent 24416c1 commit b974a34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 10 additions & 4 deletions fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,14 @@ def _list_or_args(self, keys, args):
keys.extend(args)
return keys

def pipeline(self):
"""Return an object that can be used to issue Redis commands in a batch."""
return FakePipeline(self)
def pipeline(self, transaction=True):
"""Return an object that can be used to issue Redis commands in a batch.
Arguments --
transaction (bool) -- whether the buffered commands
are issued atomically. True by default.
"""
return FakePipeline(self, transaction)


class FakePipeline(object):
Expand All @@ -885,13 +890,14 @@ class FakePipeline(object):
of their return values is returned.
"""

def __init__(self, owner):
def __init__(self, owner, transaction=True):
"""Create a pipeline for the specified FakeRedis instance.
Arguments --
owner -- a FakeRedis instance.
"""
self.owner = owner
self.transaction = transaction
self.commands = []

def __getattr__(self, name):
Expand Down
10 changes: 10 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,16 @@ def test_pipeline(self):
# Check side effects happened as expected.
self.assertEqual(['quux2', 'quux'], self.redis.lrange('baz', 0, -1))

def test_pipeline_non_transational(self):
# For our simple-minded model I don’t think
# there is any observable difference.
p = self.redis.pipeline(transaction=False)
res = p.set('baz', 'quux').get('baz').execute()

self.assertEqual([True, 'quux'], res)




@redis_must_be_running
class TestRealRedis(TestFakeRedis):
Expand Down

0 comments on commit b974a34

Please sign in to comment.