embulk-plugin-redis 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61bf03fb439dda8470f34e9da531eb3cdca993ff
4
- data.tar.gz: baff64f2a630fe88d3220bd281a1ad4e0fe9fca8
3
+ metadata.gz: c5fc0040623c35d2fb3e7fffd0e324f18bd8822a
4
+ data.tar.gz: cee02cf8f22689ea7820fd9af577539579a6d85f
5
5
  SHA512:
6
- metadata.gz: 71a2c46d0ae1631ca5bbbd414af8a7816557f12f2d881d485b2fdfd566e0a9790257f480c7e22307f674fbafcf3c66fb08564ee1033d705137cb7e87efc72d69
7
- data.tar.gz: b488de53ecb598297f2035e58140c8bf015603bf822890a28bd20ecc76bc353fe5795b5b239980dd365a59d15dd27a2939524de3aadbe98a7bb47b4757087655
6
+ metadata.gz: e1ba98a53b13bae429403b6e9a71962d45d1772c22674f3a2579b5012e404793c5a2e1d0276de2eb16d7749a9e6a09015edce029d5eac2de4b2c49a36403cf8b
7
+ data.tar.gz: 3212c1634bfb418442c5ef7c984d75e14a3a27f4f010666273905a317bb44c7825b1bc35fe2541186af2f2b6b7eecbbf879438dbaeb93ca137a91919096c3f87
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "embulk-plugin-redis"
4
- gem.version = "0.1.0"
4
+ gem.version = "0.1.1"
5
5
 
6
6
  gem.summary = %q{Embulk plugin for Redis}
7
7
  gem.description = gem.summary
@@ -2,6 +2,7 @@ module Embulk
2
2
 
3
3
  class InputRedis < InputPlugin
4
4
  require 'redis'
5
+ require 'json'
5
6
 
6
7
  Plugin.register_input('redis', self)
7
8
 
@@ -11,6 +12,7 @@ module Embulk
11
12
  'port' => config.param('port', :int, :default => 6379),
12
13
  'db' => config.param('db', :int, :default => 0),
13
14
  'key_prefix' => config.param('key_prefix', :string, :default => ''),
15
+ 'encode' => config.param('encode', :string, :default => 'json'),
14
16
  }
15
17
  threads = config.param('threads', :int, default: 1)
16
18
 
@@ -26,14 +28,19 @@ module Embulk
26
28
  return {}
27
29
  end
28
30
 
29
- def self.run(task, schema, index, page_builder)
30
- puts "Redis input thread #{index}..."
31
-
32
- r = ::Redis.new(:host => task['host'], :port => task['port'], :db => task['db'])
33
- r.keys("#{task['key_prefix']}*").each do |k|
34
- page_builder.add([k, r.get(k)])
31
+ def run
32
+ puts "Redis input thread #{@index}..."
33
+
34
+ r = Redis.new(:host => @task['host'], :port => @task['port'], :db => @task['db'])
35
+ r.keys("#{@task['key_prefix']}*").each do |k|
36
+ # TODO: Use MGET or something
37
+ case @task['encode']
38
+ when 'json'
39
+ v = r.get(k)
40
+ @page_builder.add([k, v])
41
+ end
35
42
  end
36
- page_builder.finish # don't forget to call finish :-)
43
+ @page_builder.finish # don't forget to call finish :-)
37
44
 
38
45
  commit_report = {
39
46
  }
@@ -2,6 +2,7 @@ module Embulk
2
2
 
3
3
  class OutputRedis < OutputPlugin
4
4
  require 'redis'
5
+ require 'json'
5
6
 
6
7
  Plugin.register_output('redis', self)
7
8
 
@@ -11,6 +12,8 @@ module Embulk
11
12
  'port' => config.param('port', :int, :default => 6379),
12
13
  'db' => config.param('db', :int, :default => 0),
13
14
  'key' => config.param('key', :string),
15
+ 'key_prefix' => config.param('key_prefix', :string, :default => ''),
16
+ 'encode' => config.param('encode', :string, :default => 'json'),
14
17
  }
15
18
 
16
19
  puts "Redis output started."
@@ -33,8 +36,11 @@ module Embulk
33
36
  def add(page)
34
37
  page.each do |record|
35
38
  hash = Hash[schema.names.zip(record)]
36
- puts "#{@message}: #{hash.to_json}"
37
- @redis.set(hash[task['key']], hash)
39
+ case task['encode']
40
+ when 'json'
41
+ v = hash.to_json
42
+ @redis.set("#{task['key_prefix']}#{hash[task['key']]}", v)
43
+ end
38
44
  @records += 1
39
45
  end
40
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-plugin-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitsunori Komatsu