Class: Sensu::Redis::Client

Inherits:
EM::Connection
  • Object
show all
Includes:
EM::Deferrable, Commands, Connection, Parser, Processor
Defined in:
lib/sensu/redis.rb

Class Method Summary collapse

Methods included from Connection

#after_reconnect, #before_reconnect, #close, #connected?, #connection_completed, #error, #initialize, #on_error, #reconnect!, #unbind, #validate_connection!

Methods included from Commands

#auth_and_select_db, #create_command_methods!, #get_size, #send_command, #subscribe, #unsubscribe

Methods included from Processor

#begin_multibulk, #dispatch_error, #dispatch_response, #fetch_response_callback

Methods included from Parser

#parse_line, #receive_data

Class Method Details

.connect(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/sensu/redis.rb', line 32

def connect(options={})
  if options.is_a?(String)
    options = parse_url(options)
  end
  options[:host] ||= "127.0.0.1"
  options[:port] = (options[:port] || 6379).to_i
  EM.connect(options[:host], options[:port], self, options)
end

.parse_url(url) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sensu/redis.rb', line 19

def parse_url(url)
  begin
    uri = URI.parse(url)
    {
      :host => uri.host,
      :port => uri.port,
      :password => uri.password
    }
  rescue
    raise ArgumentError, "invalid redis url"
  end
end