class Redis::Connection::Synchrony

Public Class Methods

connect(config) click to toggle source
# File lib/redis/connection/synchrony.rb, line 68
def self.connect(config)
  if config[:scheme] == "unix"
    conn = EventMachine.connect_unix_domain(config[:path], RedisClient)
  else
    conn = EventMachine.connect(config[:host], config[:port], RedisClient) do |c|
      c.pending_connect_timeout = [config[:connect_timeout], 0.1].max
    end
  end

  fiber = Fiber.current
  conn.callback { fiber.resume }
  conn.errback { fiber.resume :refused }

  raise Errno::ECONNREFUSED if Fiber.yield == :refused

  instance = new(conn)
  instance.timeout = config[:timeout]
  instance
end
new(connection) click to toggle source
# File lib/redis/connection/synchrony.rb, line 88
def initialize(connection)
  @connection = connection
end

Public Instance Methods

connected?() click to toggle source
# File lib/redis/connection/synchrony.rb, line 92
def connected?
  @connection && @connection.connected?
end
disconnect() click to toggle source
# File lib/redis/connection/synchrony.rb, line 100
def disconnect
  @connection.close_connection
  @connection = nil
end
read() click to toggle source
# File lib/redis/connection/synchrony.rb, line 109
def read
  type, payload = @connection.read

  if type == :reply
    payload
  elsif type == :error
    raise payload
  else
    raise "Unknown type #{type.inspect}"
  end
end
timeout=(timeout) click to toggle source
# File lib/redis/connection/synchrony.rb, line 96
def timeout=(timeout)
  @timeout = timeout
end
write(command) click to toggle source
# File lib/redis/connection/synchrony.rb, line 105
def write(command)
  @connection.send(build_command(command))
end