Class: Redis::Connection::Synchrony

Inherits:
Object
  • Object
show all
Includes:
CommandHelper
Defined in:
lib/redis/connection/synchrony.rb

Constant Summary

Constants included from CommandHelper

CommandHelper::COMMAND_DELIMITER

Instance Method Summary collapse

Methods included from CommandHelper

#build_command

Constructor Details

#initializeSynchrony

Returns a new instance of Synchrony.



61
62
63
64
# File 'lib/redis/connection/synchrony.rb', line 61

def initialize
  @timeout = 5_000_000
  @connection = nil
end

Instance Method Details

#connect(host, port, timeout) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/redis/connection/synchrony.rb', line 74

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

#connect_unix(path, timeout) ⇒ Object



82
83
84
85
# File 'lib/redis/connection/synchrony.rb', line 82

def connect_unix(path, timeout)
  conn = EventMachine.connect_unix_domain(path, RedisClient)
  setup_connect_callbacks(conn, Fiber.current)
end

#connected?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/redis/connection/synchrony.rb', line 66

def connected?
  @connection && @connection.connected?
end

#disconnectObject



87
88
89
90
# File 'lib/redis/connection/synchrony.rb', line 87

def disconnect
  @connection.close_connection
  @connection = nil
end

#readObject



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/redis/connection/synchrony.rb', line 96

def read
  type, payload = @connection.read

  if type == :reply
    payload
  elsif type == :error
    raise payload
  else
    raise "Unknown type #{type.inspect}"
  end
end

#timeout=(usecs) ⇒ Object



70
71
72
# File 'lib/redis/connection/synchrony.rb', line 70

def timeout=(usecs)
  @timeout = usecs
end

#write(command) ⇒ Object



92
93
94
# File 'lib/redis/connection/synchrony.rb', line 92

def write(command)
  @connection.send(build_command(command))
end