fluent-plugin-redis 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-redis"
6
- s.version = "0.1.3"
6
+ s.version = "0.2.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Yuki Nishijima"]
9
9
  s.date = %q{2011-09-30}
@@ -16,6 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_dependency %q<fluent>, ["~> 0.9.14"]
19
+ s.add_dependency %q<fluentd>, ["~> 0.10.0"]
20
20
  s.add_dependency %q<redis>, ["~> 2.2.2"]
21
21
  end
@@ -1,6 +1,7 @@
1
1
  module Fluent
2
2
  class RedisOutput < BufferedOutput
3
3
  Fluent::Plugin.register_output('redis', self)
4
+ attr_reader :host, :port, :db_number, :redis
4
5
 
5
6
  def initialize
6
7
  super
@@ -12,11 +13,11 @@ module Fluent
12
13
  super
13
14
 
14
15
  @host = conf.has_key?('host') ? conf['host'] : 'localhost'
15
- @port = conf.has_key?('port') ? conf['port'] : 6379
16
- @db = conf.has_key?('db') ? conf['db'] : nil
16
+ @port = conf.has_key?('port') ? conf['port'].to_i : 6379
17
+ @db_number = conf.has_key?('db_number') ? conf['db_number'].to_i : nil
17
18
 
18
19
  if conf.has_key?('namespace')
19
- $log.warn "Namespace option has been removed from fluent-plugin-radis 0.1.1. Please add or remove the namespace '#{conf['namespace']}' manually."
20
+ $log.warn "namespace option has been removed from fluent-plugin-redis 0.1.3. Please add or remove the namespace '#{conf['namespace']}' manually."
20
21
  end
21
22
  end
22
23
 
@@ -24,29 +25,24 @@ module Fluent
24
25
  super
25
26
 
26
27
  @redis = Redis.new(:host => @host, :port => @port,
27
- :thread_safe => true, :db => @db)
28
+ :thread_safe => true, :db => @db_number)
28
29
  end
29
30
 
30
31
  def shutdown
31
32
  @redis.quit
32
33
  end
33
34
 
34
- def format(tag, event)
35
- # event.record[:identifier]=[tag,event.time].join(".")
36
- # event.record.to_msgpack
37
- identifier=[tag,event.time].join(".")
38
- [ identifier, event.record ].to_msgpack
35
+ def format(tag, time, record)
36
+ identifier = [tag, time].join(".")
37
+ [identifier, record].to_msgpack
39
38
  end
40
39
 
41
40
  def write(chunk)
42
41
  @redis.pipelined {
43
42
  chunk.open { |io|
44
43
  begin
45
- MessagePack::Unpacker.new(io).each { |record|
46
- # identifier = record["identifier"].to_s
47
- # record.delete("identifier")
48
- # @redis.mapped_hmset identifier, record
49
- @redis.mapped_hmset record[0], record[1]
44
+ MessagePack::Unpacker.new(io).each.each_with_index { |record, index|
45
+ @redis.mapped_hmset "#{record[0]}.#{index}", record[1]
50
46
  }
51
47
  rescue EOFError
52
48
  # EOFError always occured when reached end of chunk.
@@ -0,0 +1,39 @@
1
+ require 'fluent/test'
2
+
3
+ class FileOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+
7
+ @d = create_driver %[
8
+ host localhost
9
+ port 6379
10
+ db_number 1
11
+ ]
12
+ @time = Time.parse("2011-01-02 13:14:15 UTC").to_i
13
+ end
14
+
15
+ def create_driver(conf = CONFIG)
16
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::RedisOutput).configure(conf)
17
+ end
18
+
19
+ def test_configure
20
+ assert_equal 'localhost', @d.instance.host
21
+ assert_equal 6379, @d.instance.port
22
+ assert_equal 1, @d.instance.db_number
23
+ end
24
+
25
+ def test_format
26
+ @d.emit({"a"=>1}, @time)
27
+ @d.expect_format(["test.#{@time}", {"a"=>1}].to_msgpack)
28
+ @d.run
29
+ end
30
+
31
+ def test_write
32
+ @d.emit({"a"=>2}, @time)
33
+ @d.emit({"a"=>3}, @time)
34
+ @d.run
35
+
36
+ assert_equal "2", @d.instance.redis.hget("test.#{@time}.0", "a")
37
+ assert_equal "3", @d.instance.redis.hget("test.#{@time}.1", "a")
38
+ end
39
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fluent-plugin-redis
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Yuki Nishijima
@@ -13,14 +13,14 @@ cert_chain: []
13
13
  date: 2011-09-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: fluent
16
+ name: fluentd
17
17
  prerelease: false
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.14
23
+ version: 0.10.0
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
@@ -51,6 +51,7 @@ files:
51
51
  - VERSION
52
52
  - fluent-plugin-redis.gemspec
53
53
  - lib/fluent/plugin/out_redis.rb
54
+ - test/plugin/out_redis.rb
54
55
  homepage: http://github.com/yuki24/fluent-plugin-redis
55
56
  licenses: []
56
57