Class: Redis::Connection::Synchrony
- Inherits:
-
Object
- Object
- Redis::Connection::Synchrony
show all
- Includes:
- CommandHelper
- Defined in:
- lib/redis/connection/synchrony.rb
Constant Summary
CommandHelper::COMMAND_DELIMITER
Class Method Summary
collapse
Instance Method Summary
collapse
#build_command
Constructor Details
#initialize(connection) ⇒ Synchrony
Returns a new instance of Synchrony.
104
105
106
|
# File 'lib/redis/connection/synchrony.rb', line 104
def initialize(connection)
@connection = connection
end
|
Class Method Details
.connect(config) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/redis/connection/synchrony.rb', line 74
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
|
Instance Method Details
#connected? ⇒ Boolean
108
109
110
|
# File 'lib/redis/connection/synchrony.rb', line 108
def connected?
@connection && @connection.connected?
end
|
#disconnect ⇒ Object
116
117
118
119
|
# File 'lib/redis/connection/synchrony.rb', line 116
def disconnect
@connection.close_connection
@connection = nil
end
|
#read ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/redis/connection/synchrony.rb', line 125
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) ⇒ Object
112
113
114
|
# File 'lib/redis/connection/synchrony.rb', line 112
def timeout=(timeout)
@connection.timeout = timeout
end
|
#write(command) ⇒ Object
121
122
123
|
# File 'lib/redis/connection/synchrony.rb', line 121
def write(command)
@connection.send(build_command(command))
end
|