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 9 def initialize(options = {}) @options = default_options.merge(options) validate_options configure_redis end
Public Instance Methods
close()
click to toggle source
# File lib/logstasher/device/redis.rb, line 43 def close redis.quit end
data_type()
click to toggle source
# File lib/logstasher/device/redis.rb, line 15 def data_type options[:data_type] end
key()
click to toggle source
# File lib/logstasher/device/redis.rb, line 19 def key options[:key] end
redis_options()
click to toggle source
# File lib/logstasher/device/redis.rb, line 23 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 32 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 49 def configure_redis @redis = ::Redis.new(redis_options) end
default_options()
click to toggle source
# File lib/logstasher/device/redis.rb, line 53 def default_options { key: 'logstash', data_type: 'list' } end
validate_options()
click to toggle source
# File lib/logstasher/device/redis.rb, line 57 def validate_options unless ['list', 'channel'].include?(options[:data_type]) fail 'Expected :data_type to be either "list" or "channel"' end end