embulk-plugin-redis 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/embulk-plugin-redis.gemspec +1 -1
- data/lib/embulk/input_redis.rb +14 -7
- data/lib/embulk/output_redis.rb +8 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5fc0040623c35d2fb3e7fffd0e324f18bd8822a
|
4
|
+
data.tar.gz: cee02cf8f22689ea7820fd9af577539579a6d85f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1ba98a53b13bae429403b6e9a71962d45d1772c22674f3a2579b5012e404793c5a2e1d0276de2eb16d7749a9e6a09015edce029d5eac2de4b2c49a36403cf8b
|
7
|
+
data.tar.gz: 3212c1634bfb418442c5ef7c984d75e14a3a27f4f010666273905a317bb44c7825b1bc35fe2541186af2f2b6b7eecbbf879438dbaeb93ca137a91919096c3f87
|
data/embulk-plugin-redis.gemspec
CHANGED
data/lib/embulk/input_redis.rb
CHANGED
@@ -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
|
30
|
-
puts "Redis input thread #{index}..."
|
31
|
-
|
32
|
-
r =
|
33
|
-
r.keys("#{task['key_prefix']}*").each do |k|
|
34
|
-
|
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
|
}
|
data/lib/embulk/output_redis.rb
CHANGED
@@ -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
|
-
|
37
|
-
|
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
|