Class: Fluent::RedisOutput

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRedisOutput

Returns a new instance of RedisOutput.



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

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

Instance Attribute Details

#db_numberObject (readonly)

Returns the value of attribute db_number.



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

def db_number
  @db_number
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#redisObject (readonly)

Returns the value of attribute redis.



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

def redis
  @redis
end

Instance Method Details

#configure(conf) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fluent/plugin/out_redis.rb', line 12

def configure(conf)
  super

  @host = conf.has_key?('host') ? conf['host'] : 'localhost'
  @port = conf.has_key?('port') ? conf['port'].to_i : 6379
  @db_number = conf.has_key?('db_number') ? conf['db_number'].to_i : nil

  if conf.has_key?('namespace')
    $log.warn "namespace option has been removed from fluent-plugin-redis 0.1.3. Please add or remove the namespace '#{conf['namespace']}' manually."
  end
end

#format(tag, time, record) ⇒ Object



35
36
37
38
# File 'lib/fluent/plugin/out_redis.rb', line 35

def format(tag, time, record)
  identifier = [tag, time].join(".")
  [identifier, record].to_msgpack
end

#shutdownObject



31
32
33
# File 'lib/fluent/plugin/out_redis.rb', line 31

def shutdown
  @redis.quit
end

#startObject



24
25
26
27
28
29
# File 'lib/fluent/plugin/out_redis.rb', line 24

def start
  super

  @redis = Redis.new(:host => @host, :port => @port,
                     :thread_safe => true, :db => @db_number)
end

#write(chunk) ⇒ Object



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

def write(chunk)
  @redis.pipelined {
    chunk.open { |io|
      begin
        MessagePack::Unpacker.new(io).each.each_with_index { |record, index|
          @redis.mapped_hmset "#{record[0]}.#{index}", record[1]
        }
      rescue EOFError
        # EOFError always occured when reached end of chunk.
      end
    }
  }
end