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" conn = EventMachine.connect_unix_domain(config[:path], RedisClient) 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 95 def initialize(connection) @connection = connection end
Public Instance Methods
connected?()
click to toggle source
# File lib/redis/connection/synchrony.rb, line 99 def connected? @connection && @connection.connected? end
disconnect()
click to toggle source
# File lib/redis/connection/synchrony.rb, line 107 def disconnect @connection.close_connection @connection = nil end
read()
click to toggle source
# File lib/redis/connection/synchrony.rb, line 116 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 103 def timeout=(timeout) @connection.timeout = timeout end
write(command)
click to toggle source
# File lib/redis/connection/synchrony.rb, line 112 def write(command) @connection.send(build_command(command)) end