class Redis::Connection::Synchrony
def connect(host, port, timeout)
def connect(host, port, timeout) conn = EventMachine.connect(host, port, RedisClient) do |c| c.pending_connect_timeout = [Float(timeout / 1_000_000), 0.1].max end setup_connect_callbacks(conn, Fiber.current) end
def connect_unix(path, timeout)
def connect_unix(path, timeout) conn = EventMachine.connect_unix_domain(path, RedisClient) setup_connect_callbacks(conn, Fiber.current) end
def connected?
def connected? @connection && @connection.connected? end
def disconnect
def disconnect @connection.close_connection @connection = nil end
def initialize
def initialize @timeout = 5_000_000 @connection = nil end
def read
def read type, payload = @connection.read if type == :reply payload elsif type == :error raise payload else raise "Unknown type #{type.inspect}" end end
def setup_connect_callbacks(conn, f)
def setup_connect_callbacks(conn, f) conn.callback do @connection = conn f.resume conn end conn.errback do @connection = conn f.resume :refused end r = Fiber.yield raise Errno::ECONNREFUSED if r == :refused r end
def timeout=(usecs)
def timeout=(usecs) @timeout = usecs end
def write(command)
def write(command) @connection.send(build_command(command)) end