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 10 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 44 def close redis.quit end
data_type()
click to toggle source
# File lib/logstasher/device/redis.rb, line 16 def data_type options[:data_type] end
key()
click to toggle source
# File lib/logstasher/device/redis.rb, line 20 def key options[:key] end
redis_options()
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
configure_redis()
click to toggle source
# File lib/logstasher/device/redis.rb, line 50 def configure_redis @redis = ::Redis.new(redis_options) end
default_options()
click to toggle source
# File lib/logstasher/device/redis.rb, line 54 def default_options { key: 'logstash', data_type: 'list' } end
validate_options()
click to toggle source
# File lib/logstasher/device/redis.rb, line 58 def validate_options unless %w[list channel].include?(options[:data_type]) raise 'Expected :data_type to be either "list" or "channel"' end end