class LogStasher::Device::Redis

Attributes

options[R]
redis[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/logstasher/device/redis.rb, line 11
def initialize(options = {})
  @options = default_options.merge(stringify_keys(options))

  validate_options
  configure_redis
end

Public Instance Methods

close() click to toggle source
# File lib/logstasher/device/redis.rb, line 46
def close
  redis.quit
end
data_type() click to toggle source
# File lib/logstasher/device/redis.rb, line 18
def data_type
  options['data_type']
end
key() click to toggle source
# File lib/logstasher/device/redis.rb, line 22
def key
  options['key']
end
redis_options() click to toggle source
# File lib/logstasher/device/redis.rb, line 26
def redis_options
  unless @redis_options
    default_keys = default_options.keys
    @redis_options = options.select { |k, v| !default_keys.include?(k) }
  end

  @redis_options
end
write(log) click to toggle source
# File lib/logstasher/device/redis.rb, line 35
def write(log)
  case data_type
  when 'list'
    redis.rpush(key, log)
  when 'channel'
    redis.publish(key, log)
  else
    fail "Unknown data type #{data_type}"
  end
end

Private Instance Methods

configure_redis() click to toggle source
# File lib/logstasher/device/redis.rb, line 52
def configure_redis
  @redis = ::Redis.new(redis_options)
end
default_options() click to toggle source
# File lib/logstasher/device/redis.rb, line 56
def default_options
  { 'key' => 'logstash', 'data_type' => 'list' }
end
validate_options() click to toggle source
# File lib/logstasher/device/redis.rb, line 60
def validate_options
  unless ['list', 'channel'].include?(options['data_type'])
    fail RuntimeError, 'Expected data_type to be either "list" or "channel"'
  end
end