Skip to content

Commit

Permalink
Allow pipelined calls within multi blocks (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
brucek authored and sds committed Nov 16, 2016
1 parent 6827465 commit 0261c2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/mock_redis/transaction_wrapper.rb
Expand Up @@ -87,6 +87,10 @@ def multi
end
end

def pipelined
yield(self) if block_given?
end

def unwatch
'OK'
end
Expand Down
14 changes: 13 additions & 1 deletion spec/transactions_spec.rb
Expand Up @@ -17,7 +17,7 @@
end.should raise_error(Redis::CommandError)
end

it 'cleans state of tansaction wrapper if exception occurs during transaction' do
it 'cleans state of transaction wrapper if exception occurs during transaction' do
lambda do
@redises.mock.multi do |_r|
raise "i'm a command that fails"
Expand Down Expand Up @@ -55,6 +55,18 @@
end.should raise_error(Redis::CommandError)
end
end

it 'allows pipelined calls within multi blocks' do
@redises.set('counter', 5)
@redises.multi do |r|
r.pipelined do |pr|
pr.set('test', 1)
pr.incr('counter')
end
end
@redises.get('counter').should == '6'
@redises.get('test').should == '1'
end
end

context '#discard' do
Expand Down

0 comments on commit 0261c2e

Please sign in to comment.