class Redis::Connection::Synchrony
Public Class Methods
connect(config)
click to toggle source
# File lib/redis/connection/synchrony.rb, line 73 def self.connect(config) if config[:scheme] == "unix" begin conn = EventMachine.connect_unix_domain(config[:path], RedisClient) rescue RuntimeError => e if e.message == "no connection" raise Errno::ECONNREFUSED else raise e end end elsif config[:scheme] == "rediss" || config[:ssl] raise NotImplementedError, "SSL not supported by synchrony driver" 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[:read_timeout] instance end
new(connection)
click to toggle source
# File lib/redis/connection/synchrony.rb, line 103 def initialize(connection) @connection = connection end
Public Instance Methods
connected?()
click to toggle source
# File lib/redis/connection/synchrony.rb, line 107 def connected? @connection && @connection.connected? end
disconnect()
click to toggle source
# File lib/redis/connection/synchrony.rb, line 115 def disconnect @connection.close_connection @connection = nil end
read()
click to toggle source
# File lib/redis/connection/synchrony.rb, line 124 def read type, payload = @connection.read if type == :reply payload elsif type == :error raise payload elsif type == :timeout raise TimeoutError else raise "Unknown type #{type.inspect}" end end
timeout=(timeout)
click to toggle source
# File lib/redis/connection/synchrony.rb, line 111 def timeout=(timeout) @connection.timeout = timeout end
write(command)
click to toggle source
# File lib/redis/connection/synchrony.rb, line 120 def write(command) @connection.send(build_command(command)) end