Skip to content

Commit

Permalink
Clean up transaction on client-side errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrk committed Dec 27, 2010
1 parent f00ec5d commit c9b3ed2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/redis.lua
Expand Up @@ -451,11 +451,12 @@ do
end
return replies
end
local success, retval = assert(coroutine.resume(coro))

if #queued_parsers == 0 then

local success, retval = coroutine.resume(coro)
if #queued_parsers == 0 or not success then
client:discard()
return replies
assert(success, retval)
return replies
end

local raw_replies = client:exec()
Expand Down
10 changes: 10 additions & 0 deletions test/test_client.lua
Expand Up @@ -2104,6 +2104,16 @@ context("Redis commands", function()
assert_response_queued(t:exists('foo'))
end)
assert_table_values(replies, { true, 'hello', 'redis', false })

-- clean up transaction after client-side errors
assert_error(function()
redis:transaction(function(t)
t:lpush('metavars', 'foo')
error('whoops!')
t:lpush('metavars', 'hoge')
end)
end)
assert_false(redis:exists('metavars'))
end)

test("WATCH / MULTI / EXEC abstraction", function()
Expand Down

0 comments on commit c9b3ed2

Please sign in to comment.