Class: LogStasher::Device::Redis

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogStasher::Device

factory, stringify_keys

Constructor Details

#initialize(options = {}) ⇒ Redis

Returns a new instance of Redis.



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

def initialize(options = {})
  @options = default_options.merge(stringify_keys(options))

  validate_options
  configure_redis
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#redisObject (readonly)

Returns the value of attribute redis.



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

def redis
  @redis
end

Instance Method Details

#closeObject



46
47
48
# File 'lib/logstasher/device/redis.rb', line 46

def close
  redis.quit
end

#data_typeObject



18
19
20
# File 'lib/logstasher/device/redis.rb', line 18

def data_type
  options['data_type']
end

#keyObject



22
23
24
# File 'lib/logstasher/device/redis.rb', line 22

def key
  options['key']
end

#redis_optionsObject



26
27
28
29
30
31
32
33
# 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) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# 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