Skip to content
Browse files

Raise on #read when the connection is closed

  • Loading branch information...
1 parent 7bdafbf commit 6e3f954c2e3dc8d4e2cb4de8426adaaf0285e5c8 @pietern pietern committed Mar 29, 2011
Showing with 16 additions and 9 deletions.
  1. +13 −9 lib/redis/connection/synchrony.rb
  2. +3 −0 test/synchrony_driver.rb
View
22 lib/redis/connection/synchrony.rb
@@ -22,18 +22,16 @@ def receive_data(data)
begin
until (reply = @reader.gets) == false
- @req.succeed reply
+ @req.succeed [:reply, reply]
end
rescue RuntimeError => err
- @req.fail ::Redis::ProtocolError.new(err.message)
+ @req.fail [:error, ::Redis::ProtocolError.new(err.message)]
end
end
def read
@req = EventMachine::DefaultDeferrable.new
- r = EventMachine::Synchrony.sync @req
- raise r if r.is_a?(::Redis::ProtocolError)
- r
+ EventMachine::Synchrony.sync @req
end
def send(data)
@@ -42,7 +40,7 @@ def send(data)
def unbind
if @req
- @req.fail
+ @req.fail [:error, Errno::ECONNRESET]
@req = nil
else
fail
@@ -91,9 +89,15 @@ def write(command)
end
def read
- @connection.read
- rescue RuntimeError => err
- raise ::Redis::ProtocolError.new(err.message)
+ type, payload = @connection.read
+
+ if type == :reply
+ payload
+ elsif type == :error
+ raise payload
+ else
+ raise "Unknown type #{type.inspect}"
+ end
end
private
View
3 test/synchrony_driver.rb
@@ -50,5 +50,8 @@
assert "s2" == r.lpop("foo")
assert "s1" == r.lpop("foo")
+ assert "OK" == r.client.call(:quit)
+ assert "PONG" == r.ping
+
EM.stop
end

0 comments on commit 6e3f954

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