Class: Redis::Connection::RedisClient
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Redis::Connection::RedisClient
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/redis/connection/synchrony.rb
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #connection_completed ⇒ Object
- #post_init ⇒ Object
- #read ⇒ Object
- #receive_data(data) ⇒ Object
- #send(data) ⇒ Object
- #unbind ⇒ Object
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
20 21 22 |
# File 'lib/redis/connection/synchrony.rb', line 20 def timeout @timeout end |
Instance Method Details
#connected? ⇒ Boolean
33 34 35 |
# File 'lib/redis/connection/synchrony.rb', line 33 def connected? @connected end |
#connection_completed ⇒ Object
28 29 30 31 |
# File 'lib/redis/connection/synchrony.rb', line 28 def connection_completed @connected = true succeed end |
#post_init ⇒ Object
22 23 24 25 26 |
# File 'lib/redis/connection/synchrony.rb', line 22 def post_init @req = nil @connected = false @reader = ::Hiredis::Reader.new end |
#read ⇒ Object
55 56 57 58 59 |
# File 'lib/redis/connection/synchrony.rb', line 55 def read @req = EventMachine::DefaultDeferrable.new @req.timeout(@timeout, :timeout) if @timeout > 0 EventMachine::Synchrony.sync @req end |
#receive_data(data) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/redis/connection/synchrony.rb', line 37 def receive_data(data) @reader.feed(data) loop do begin reply = @reader.gets rescue RuntimeError => err @req.fail [:error, ProtocolError.new(err.)] break end break if reply == false reply = CommandError.new(reply.) if reply.is_a?(RuntimeError) @req.succeed [:reply, reply] end end |
#send(data) ⇒ Object
61 62 63 |
# File 'lib/redis/connection/synchrony.rb', line 61 def send(data) callback { send_data data } end |
#unbind ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/redis/connection/synchrony.rb', line 65 def unbind @connected = false if @req @req.fail [:error, Errno::ECONNRESET] @req = nil else fail end end |