class Output::RedisPlugin

Public Class Methods

new(options) click to toggle source

Create a redis output plugin instance

@param [Hash] options @option options [String] :uri redis URI string @option options [String] :host @option options [Integer] :port @option options [Integer] :db @option options [String] :password @option options [String] :key redis key

# File lib/fileminer/output/redis.rb, line 19
def initialize(options)
  uri = options[:uri]
  if uri.nil?
    uri = parse_uri options
  end
  @key = options[:key]
  raise 'Missing key config on output.redis' if @key.nil?
  driver = require_lib?('hiredis') ? :hiredis : :ruby
  @redis = Redis.new url: uri, driver: driver
end

Public Instance Methods

send_all(lines, &listener) click to toggle source

Send all lines to redis using LPUSH @key

@param [Array] lines @yield a listener to be called after all lines just be sent

# File lib/fileminer/output/redis.rb, line 55
def send_all(lines, &listener)
  messages = lines.map { |line| line.to_json }
  @redis.lpush @key, messages
  listener.call
end

Private Instance Methods

parse_uri(options) click to toggle source
# File lib/fileminer/output/redis.rb, line 31
def parse_uri(options)
  host = options[:host] || 'localhost'
  port = options[:port] || 6379
  db = options[:db] || 0
  password = options[:password]
  if password.nil?
    "redis://#{host}:#{port}/#{db}"
  else
    "redis://:#{password}@#{host}:#{port}/#{db}"
  end
end
require_lib?(name) click to toggle source
# File lib/fileminer/output/redis.rb, line 43
def require_lib?(name)
  require name
rescue LoadError
  false
end