Class: Fluent::MemcachedOutput

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemcachedOutput

Returns a new instance of MemcachedOutput.



5
6
7
8
# File 'lib/fluent/plugin/out_memcached.rb', line 5

def initialize
  super
  require 'dalli'
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/fluent/plugin/out_memcached.rb', line 3

def host
  @host
end

#memcachedObject (readonly)

Returns the value of attribute memcached.



3
4
5
# File 'lib/fluent/plugin/out_memcached.rb', line 3

def memcached
  @memcached
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/fluent/plugin/out_memcached.rb', line 3

def port
  @port
end

Instance Method Details

#configure(conf) ⇒ Object



10
11
12
13
14
# File 'lib/fluent/plugin/out_memcached.rb', line 10

def configure(conf)
  super
  @host = conf.has_key?('host') ? conf['host'] : 'localhost'
  @port = conf.has_key?('port') ? conf['port'].to_i : 11211
end

#format(tag, time, record) ⇒ Object



25
26
27
# File 'lib/fluent/plugin/out_memcached.rb', line 25

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#shutdownObject



21
22
23
# File 'lib/fluent/plugin/out_memcached.rb', line 21

def shutdown
  @memcached.close
end

#startObject



16
17
18
19
# File 'lib/fluent/plugin/out_memcached.rb', line 16

def start
  super
  @memcached = Dalli::Client.new("#{host}:#{port}")
end

#write(chunk) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/fluent/plugin/out_memcached.rb', line 29

def write(chunk)
  chunk.msgpack_each { |tag, time, record|
    key = record.values.first
    value = record.values.drop(1).join(' ')
    @memcached.set key, value
  }
end