module Sensu::Redis

Constants

ASTERISK
AUTH_COMMAND

Redis commands.

BOOLEAN_PROCESSOR

Boolean Redis response value processor.

COLON
COMMANDS

Redis commands that are supported by this library.

DELIM
DOLLAR
INCOMPLETE

Redis response line parser incomplete data return value.

INFO_COMMAND
MINUS
OK

RESP (REdis Serialization Protocol) response type characters and delimiter (redis.io/topics/protocol).

PLUS
PUBSUB_RESPONSES

Redis pubsub response type values.

RESPONSE_PROCESSORS

Redis response value processors.

SELECT_COMMAND
SUBSCRIBE_COMMAND
TRUE_VALUES

Redis response boolean values.

UNSUBSCRIBE_COMMAND

Public Class Methods

connect(options={}, &block) click to toggle source

Connect to Redis using the provided connection options.

@param options [String,Hash] @yield callback to be called with the redis connection object.

# File lib/sensu/redis.rb, line 55
def connect(options={}, &block)
  case options
  when String
    options = parse_url(options)
  when nil
    options = {}
  end
  options[:host] ||= "127.0.0.1"
  options[:port] ||= 6379
  if options[:sentinels].is_a?(Array) && options[:sentinels].length > 0
    connect_via_sentinel(options, &block)
  else
    connect_direct(options, &block)
  end
end
connect_direct(options, &block) click to toggle source

Connect to the current Redis master directly, using the provided connection options.

@param options [Hash] @yield callback to be called with the redis connection object.

# File lib/sensu/redis.rb, line 47
def connect_direct(options, &block)
  block.call(EM.connect(options[:host], options[:port], Client, options))
end
connect_via_sentinel(options, &block) click to toggle source

Connect to the current Redis master via Sentinel. Sentinel will resolve the current Redis master host and port.

@param options [Hash] @yield callback to be called with the redis connection object.

# File lib/sensu/redis.rb, line 33
def connect_via_sentinel(options, &block)
  sentinel = Sentinel.new(options)
  sentinel.resolve do |host, port|
    redis = EM.connect(host, port, Client, options)
    redis.sentinel = sentinel
    block.call(redis)
  end
end
parse_url(url) click to toggle source

Parse a Redis URL. An argument error exception is thrown if this method is unable to parse the provided URL string.

@param url [String] @return [Hash] Redis connection options.

# File lib/sensu/redis.rb, line 15
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