Class: Fluent::RedisListOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_redislist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRedisListOutput

Returns a new instance of RedisListOutput.



6
7
8
9
10
11
12
# File 'lib/fluent/plugin/out_redislist.rb', line 6

def initialize
  super
  require 'redis'
  require 'msgpack'
  require 'socket'
  require 'json'
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



4
5
6
# File 'lib/fluent/plugin/out_redislist.rb', line 4

def database
  @database
end

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/fluent/plugin/out_redislist.rb', line 4

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



4
5
6
# File 'lib/fluent/plugin/out_redislist.rb', line 4

def port
  @port
end

#redisObject (readonly)

Returns the value of attribute redis.



4
5
6
# File 'lib/fluent/plugin/out_redislist.rb', line 4

def redis
  @redis
end

Instance Method Details

#configure(conf) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/fluent/plugin/out_redislist.rb', line 14

def configure(conf)
  super

  @host = conf['host'] || 'localhost'
  @port = ( conf['port'] || '6379' ).to_i
  @database = ( conf['database'] || '0' ).to_i
end

#format(tag, time, record) ⇒ Object



33
34
35
36
37
38
# File 'lib/fluent/plugin/out_redislist.rb', line 33

def format(tag, time, record)
  record["@node"] = @whereami
  record["@timestamp"] = Time.at(time).to_s # to avoid LOGSTASH-1340
  record["@key"] = tag
  record.to_msgpack
end

#shutdownObject



29
30
31
# File 'lib/fluent/plugin/out_redislist.rb', line 29

def shutdown
  @redis.quit
end

#startObject



22
23
24
25
26
27
# File 'lib/fluent/plugin/out_redislist.rb', line 22

def start
  super

  @whereami = Socket.gethostname
  @redis = Redis.new(:host => @host, :port => @port, :db => @database)
end

#write(chunk) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fluent/plugin/out_redislist.rb', line 40

def write(chunk)
  @redis.pipelined {
    chunk.open { |io|
      begin
        MessagePack::Unpacker.new(io).each { |record|
          key = record.delete('@key')
          @redis.rpush key, record.to_json
        }
      rescue EOFError
        # EOFError always occured when reached end of chunk.
      end
    }
  }
end