Class: Output::RedisPlugin

Inherits:
OutputPlugin show all
Defined in:
lib/fileminer/output/redis.rb

Instance Method Summary collapse

Methods inherited from OutputPlugin

#batch?, #close

Constructor Details

#initialize(options) ⇒ RedisPlugin

Create a redis output plugin instance

Parameters:

Options Hash (options):

  • :uri (String)

    redis URI string

  • :host (String)
  • :port (Integer)
  • :db (Integer)
  • :password (String)
  • :key (String)

    redis key



19
20
21
22
23
24
25
26
27
28
# 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

Instance Method Details

#send_all(lines, &listener) ⇒ Object



55
56
57
58
59
# 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