Class: LogStasher::Device::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/logstasher/device/redis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Redis

Returns a new instance of Redis.



10
11
12
13
14
# File 'lib/logstasher/device/redis.rb', line 10

def initialize(options = {})
  @options = default_options.merge(options)
  validate_options
  configure_redis
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/logstasher/device/redis.rb', line 8

def options
  @options
end

#redisObject (readonly)

Returns the value of attribute redis.



8
9
10
# File 'lib/logstasher/device/redis.rb', line 8

def redis
  @redis
end

Instance Method Details

#closeObject



44
45
46
# File 'lib/logstasher/device/redis.rb', line 44

def close
  redis.quit
end

#data_typeObject



16
17
18
# File 'lib/logstasher/device/redis.rb', line 16

def data_type
  options[:data_type]
end

#keyObject



20
21
22
# File 'lib/logstasher/device/redis.rb', line 20

def key
  options[:key]
end

#redis_optionsObject



24
25
26
27
28
29
30
31
# File 'lib/logstasher/device/redis.rb', line 24

def redis_options
  unless @redis_options
    default_keys = default_options.keys
    @redis_options = options.reject { |k, _v| default_keys.include?(k) }
  end

  @redis_options
end

#write(log) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/logstasher/device/redis.rb', line 33

def write(log)
  case data_type
  when 'list'
    redis.rpush(key, log)
  when 'channel'
    redis.publish(key, log)
  else
    raise "Unknown data type #{data_type}"
  end
end