Class: Embulk::OutputRedis
- Inherits:
-
OutputPlugin
- Object
- OutputPlugin
- Embulk::OutputRedis
- Defined in:
- lib/embulk/output/redis.rb
Class Method Summary collapse
Instance Method Summary collapse
- #abort ⇒ Object
- #add(page) ⇒ Object
- #close ⇒ Object
- #commit ⇒ Object
- #finish ⇒ Object
-
#initialize(task, schema, index) ⇒ OutputRedis
constructor
A new instance of OutputRedis.
Constructor Details
#initialize(task, schema, index) ⇒ OutputRedis
Returns a new instance of OutputRedis.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/embulk/output/redis.rb', line 25 def initialize(task, schema, index) puts "Example output thread #{index}..." super @records = 0 if task['url'].nil? || task['url'].empty? @redis = ::Redis.new(:host => task['host'], :port => task['port'], :db => task['db']) else @redis = ::Redis.new(:url => task['url']) end end |
Class Method Details
.transaction(config, schema, processor_count, &control) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/embulk/output/redis.rb', line 8 def self.transaction(config, schema, processor_count, &control) task = { 'host' => config.param('host', :string, :default => 'localhost'), 'port' => config.param('port', :integer, :default => 6379), 'db' => config.param('db', :integer, :default => 0), 'key' => config.param('key', :string), 'url' => config.param('url', :string), 'is_json' => config.param('is_json', :bool, :default => false), } puts "Redis output started." commit_reports = yield(task) puts "Redis output finished. Commit reports = #{commit_reports.to_json}" return {} end |
Instance Method Details
#abort ⇒ Object
58 59 |
# File 'lib/embulk/output/redis.rb', line 58 def abort end |
#add(page) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/embulk/output/redis.rb', line 39 def add(page) page.each do |record| hash = Hash[schema.names.zip(record)] puts "#{@message}: #{hash.to_json}" # puts "key field: #{task['key']}" # puts "key: #{record[0][task['key']]}" # If the data being stored is known to be JSON. if task['is_json'] @redis.set(record[0][task['key']], record[0].to_json) else @redis.set(hash[task['key']], hash) end @records += 1 end end |
#close ⇒ Object
36 37 |
# File 'lib/embulk/output/redis.rb', line 36 def close end |
#commit ⇒ Object
61 62 63 64 65 66 |
# File 'lib/embulk/output/redis.rb', line 61 def commit commit_report = { "records" => @records } return commit_report end |
#finish ⇒ Object
55 56 |
# File 'lib/embulk/output/redis.rb', line 55 def finish end |