module Redis::Connection::SocketMixin
Constants
- CRLF
- NBIO_EXCEPTIONS
Exceptions raised during non-blocking I/O ops that require retrying the op
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/redis/connection/ruby.rb, line 23 def initialize(*args) super(*args) @timeout = @write_timeout = nil @buffer = "" end
Public Instance Methods
_read_from_socket(nbytes)
click to toggle source
# File lib/redis/connection/ruby.rb, line 66 def _read_from_socket(nbytes) begin read_nonblock(nbytes) rescue *NBIO_EXCEPTIONS if IO.select([self], nil, nil, @timeout) retry else raise Redis::TimeoutError end end rescue EOFError raise Errno::ECONNRESET end
gets()
click to toggle source
# File lib/redis/connection/ruby.rb, line 56 def gets crlf = nil while (crlf = @buffer.index(CRLF)) == nil @buffer << _read_from_socket(1024) end @buffer.slice!(0, crlf + CRLF.bytesize) end
read(nbytes)
click to toggle source
# File lib/redis/connection/ruby.rb, line 46 def read(nbytes) result = @buffer.slice!(0, nbytes) while result.bytesize < nbytes result << _read_from_socket(nbytes - result.bytesize) end result end
timeout=(timeout)
click to toggle source
# File lib/redis/connection/ruby.rb, line 30 def timeout=(timeout) if timeout && timeout > 0 @timeout = timeout else @timeout = nil end end
write(*args)
click to toggle source
UNIXSocket and TCPSocket don't support write timeouts
Calls superclass method
# File lib/redis/connection/ruby.rb, line 84 def write(*args) Timeout.timeout(@write_timeout, TimeoutError) { super } end
write_timeout=(timeout)
click to toggle source
# File lib/redis/connection/ruby.rb, line 38 def write_timeout=(timeout) if timeout && timeout > 0 @write_timeout = timeout else @write_timeout = nil end end