embulk-plugin-redis 0.1.2 → 0.1.3
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/README.md +10 -6
- data/embulk-plugin-redis.gemspec +1 -1
- data/lib/embulk/output_redis.rb +15 -4
- metadata +2 -2
data/README.md
CHANGED
@@ -6,11 +6,14 @@ This plugin runs without transaction for now.
|
|
6
6
|
|
7
7
|
## Configuration
|
8
8
|
|
9
|
-
- **host**
|
10
|
-
- **port**
|
11
|
-
- **db**
|
12
|
-
- **key_prefix**
|
13
|
-
- **
|
9
|
+
- **host** Hostname of the Redis server (string, default: "localhost")
|
10
|
+
- **port** Port of the Redis server (integer, default: 6379)
|
11
|
+
- **db** Database number (integer, default: 0)
|
12
|
+
- **key_prefix** Key prefix for input/output plugin (string)
|
13
|
+
- **encode** Encoding in Redis
|
14
|
+
- json: Stored as a JSON string. GET/SET commands can access it (string)
|
15
|
+
- hash: Stored as a Hash. H* commands such as HMGET/HMSET can access it (string, output only)
|
16
|
+
- **key** Column name used for a key in Redis (string, required: output only)
|
14
17
|
|
15
18
|
### Example
|
16
19
|
|
@@ -22,7 +25,7 @@ out:
|
|
22
25
|
db: 0
|
23
26
|
key: user_name
|
24
27
|
key_prefix: user_
|
25
|
-
|
28
|
+
encode: hash
|
26
29
|
|
27
30
|
in:
|
28
31
|
type: redis
|
@@ -30,5 +33,6 @@ in:
|
|
30
33
|
port: 6379
|
31
34
|
db: 0
|
32
35
|
key_prefix: user_
|
36
|
+
encode: json
|
33
37
|
```
|
34
38
|
|
data/embulk-plugin-redis.gemspec
CHANGED
data/lib/embulk/output_redis.rb
CHANGED
@@ -3,6 +3,7 @@ module Embulk
|
|
3
3
|
class OutputRedis < OutputPlugin
|
4
4
|
require 'redis'
|
5
5
|
require 'json'
|
6
|
+
require 'set'
|
6
7
|
|
7
8
|
Plugin.register_output('redis', self)
|
8
9
|
|
@@ -26,7 +27,8 @@ module Embulk
|
|
26
27
|
def initialize(task, schema, index)
|
27
28
|
puts "Example output thread #{index}..."
|
28
29
|
super
|
29
|
-
@
|
30
|
+
@rows = 0
|
31
|
+
@unique_keys = ::Set.new
|
30
32
|
@redis = ::Redis.new(:host => task['host'], :port => task['port'], :db => task['db'])
|
31
33
|
end
|
32
34
|
|
@@ -36,12 +38,20 @@ module Embulk
|
|
36
38
|
def add(page)
|
37
39
|
page.each do |record|
|
38
40
|
hash = Hash[schema.names.zip(record)]
|
41
|
+
k = "#{task['key_prefix']}#{hash[task['key']]}"
|
42
|
+
unless @unique_keys.include? k
|
39
43
|
case task['encode']
|
40
44
|
when 'json'
|
41
45
|
v = hash.to_json
|
42
|
-
@redis.set(
|
46
|
+
@redis.set(k, v)
|
47
|
+
when 'hash'
|
48
|
+
@redis.hmset(k, hash.to_a.flatten)
|
43
49
|
end
|
44
|
-
|
50
|
+
@unique_keys << k
|
51
|
+
else
|
52
|
+
puts "Warning: #{k} is already exists"
|
53
|
+
end
|
54
|
+
@rows += 1 # inrement anyway
|
45
55
|
end
|
46
56
|
end
|
47
57
|
|
@@ -53,7 +63,8 @@ module Embulk
|
|
53
63
|
|
54
64
|
def commit
|
55
65
|
commit_report = {
|
56
|
-
"
|
66
|
+
"rows" => @rows,
|
67
|
+
"unique_keys" => @unique_keys.size
|
57
68
|
}
|
58
69
|
return commit_report
|
59
70
|
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.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|