embulk-output-rediskeys 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +3 -0
- data/embulk-output-rediskeys.gemspec +21 -0
- data/lib/embulk/output/rediskeys.rb +107 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c149c7821c9ddb31512c2f1d70b6ee210f41f59
|
4
|
+
data.tar.gz: 16154b58ad4f0926d5ea54a6cf3335bda2c25d7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 32f24d5b23ac98f6c3d767370fbc13f0323f13cc2f4cf4b53ce6b982e8e993a6c3fd164bbf7c0511b68f5aedd286018f791dc1f0f6b923926226d5bcf863ee95
|
7
|
+
data.tar.gz: 483793a9bc6f926dbe6f1a487acd3863434fd5e2631e1436064debe1107e006d8d26a1789c1ea3207860b3404f640a4dd7f8c26a7acaf0a669b6d6eaa3f4ef32
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.0.4.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Rediskeys output plugin for Embulk
|
2
|
+
|
3
|
+
|
4
|
+
## Overview
|
5
|
+
|
6
|
+
* **Plugin type**: output
|
7
|
+
* **Load all or nothing**: no
|
8
|
+
* **Resume supported**: no
|
9
|
+
* **Cleanup supported**: yes
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
- host: Redis hostname (string, default:localhost).
|
14
|
+
- port: Redis port number (int, default: 6379).
|
15
|
+
- db: Number of Redis DB to dump columns (int, default: 0).
|
16
|
+
- key_prefix: Prefix of column name to set. (string, required).
|
17
|
+
- encode: Type of eoncoding of data to set (string, default:json).
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
```yaml
|
22
|
+
out:
|
23
|
+
type: rediskeys
|
24
|
+
host: localhost
|
25
|
+
port: 6379
|
26
|
+
db: 4
|
27
|
+
key_prefix: test_key
|
28
|
+
encode: json
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
## Build
|
33
|
+
|
34
|
+
```
|
35
|
+
$ rake
|
36
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-output-rediskeys"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["dokuma"]
|
6
|
+
spec.summary = "Redis output plugin for Embulk"
|
7
|
+
spec.description = "Dumps records to Redis."
|
8
|
+
spec.email = ["dokuma.h@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/dokuma/embulk-output-rediskeys"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
spec.has_rdoc = false
|
16
|
+
|
17
|
+
spec.add_dependency 'redis', ['>= 3.0.5']
|
18
|
+
spec.add_development_dependency 'embulk', ['>= 0.8.9']
|
19
|
+
spec.add_development_dependency 'bundler', ['>= 1.10.6']
|
20
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
21
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module Embulk
|
2
|
+
module Output
|
3
|
+
|
4
|
+
class Redis < OutputPlugin
|
5
|
+
require 'redis'
|
6
|
+
require 'json'
|
7
|
+
require 'set'
|
8
|
+
|
9
|
+
Plugin.register_output("rediskeys", self)
|
10
|
+
|
11
|
+
def self.transaction(config, schema, count, &control)
|
12
|
+
# configuration code:
|
13
|
+
task = {
|
14
|
+
'host' => config.param('host', :string, :default => 'localhost'),
|
15
|
+
'port' => config.param('port', :integer, :default => 6379),
|
16
|
+
'db' => config.param('db', :integer, :default => 0),
|
17
|
+
'key_prefix' => config.param('key_prefix', :string, :default => ''),
|
18
|
+
'encode' => config.param('encode', :string, :default => 'json')
|
19
|
+
}
|
20
|
+
|
21
|
+
# resumable output:
|
22
|
+
# resume(task, schema, count, &control)
|
23
|
+
|
24
|
+
# non-resumable output:
|
25
|
+
task_reports = yield(task)
|
26
|
+
puts "Redis output finished. Commit reports = #{task_reports.to_json}"
|
27
|
+
|
28
|
+
next_config_diff = {}
|
29
|
+
return next_config_diff
|
30
|
+
end
|
31
|
+
|
32
|
+
#def self.resume(task, schema, count, &control)
|
33
|
+
# task_reports = yield(task)
|
34
|
+
#
|
35
|
+
# next_config_diff = {}
|
36
|
+
# return next_config_diff
|
37
|
+
#end
|
38
|
+
|
39
|
+
def init
|
40
|
+
# initialization code:
|
41
|
+
puts "Redis output thread #{index}..."
|
42
|
+
super
|
43
|
+
@rows = 0
|
44
|
+
@processed_keys = [].to_set
|
45
|
+
@unique_keys = [].to_set
|
46
|
+
@redis = ::Redis.new(:host => task['host'], :port => task['port'], :db => task['db'])
|
47
|
+
end
|
48
|
+
|
49
|
+
def close
|
50
|
+
end
|
51
|
+
|
52
|
+
def add(page)
|
53
|
+
# output code:
|
54
|
+
page.each do |records|
|
55
|
+
puts "Schema: #{schema.names}"
|
56
|
+
# puts "Record: #{records}"
|
57
|
+
records.each do |record|
|
58
|
+
hash = JSON.parse(record)
|
59
|
+
|
60
|
+
k = nil
|
61
|
+
v = hash.select{|key,v|
|
62
|
+
k = key
|
63
|
+
key.match(/^#{task['key_prefix']}/)
|
64
|
+
}
|
65
|
+
|
66
|
+
puts "KEY: #{k}"
|
67
|
+
|
68
|
+
@processed_keys << k
|
69
|
+
unless @unique_keys.include? k
|
70
|
+
case task['encode']
|
71
|
+
when 'json'
|
72
|
+
v = v[k].to_json
|
73
|
+
@redis.set(k, v)
|
74
|
+
when 'hash'
|
75
|
+
v = v[k]
|
76
|
+
puts "VALUE: #{v}"
|
77
|
+
puts "FLATTEN: #{v.to_a.flatten}"
|
78
|
+
@redis.hmset(k, v.to_a.flatten)
|
79
|
+
end
|
80
|
+
@unique_keys << k
|
81
|
+
else
|
82
|
+
puts "Warning: #{k} is already exists"
|
83
|
+
end
|
84
|
+
@rows += 1 # inrement anyway
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def finish
|
90
|
+
end
|
91
|
+
|
92
|
+
def abort
|
93
|
+
end
|
94
|
+
|
95
|
+
def commit
|
96
|
+
task_report = {
|
97
|
+
"rows" => @rows,
|
98
|
+
"processed_keys" => @processed_keys.inspect,
|
99
|
+
"unique_keys" => @unique_keys.inspect
|
100
|
+
}
|
101
|
+
return task_report
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-output-rediskeys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- dokuma
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: embulk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.9
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.9
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.10.6
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.10.6
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Dumps records to Redis.
|
70
|
+
email:
|
71
|
+
- dokuma.h@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- embulk-output-rediskeys.gemspec
|
83
|
+
- lib/embulk/output/rediskeys.rb
|
84
|
+
homepage: https://github.com/dokuma/embulk-output-rediskeys
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.5.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Redis output plugin for Embulk
|
108
|
+
test_files: []
|