Class: Embulk::OutputRedis

Inherits:
OutputPlugin
  • Object
show all
Defined in:
lib/embulk/output_redis.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, schema, index) ⇒ OutputRedis

Returns a new instance of OutputRedis.



23
24
25
26
27
28
# File 'lib/embulk/output_redis.rb', line 23

def initialize(task, schema, index)
  puts "Example output thread #{index}..."
  super
  @records = 0
  @redis = ::Redis.new(:host => task['host'], :port => task['port'], :db => task['db'])
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
# 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', :int, :default => 6379),
    'db' => config.param('db', :int, :default => 0),
    'key' => config.param('key', :string),
  }

  puts "Redis output started."
  commit_reports = yield(task)
  puts "Redis output finished. Commit reports = #{commit_reports.to_json}"

  return {}
end

Instance Method Details

#abortObject



45
46
# File 'lib/embulk/output_redis.rb', line 45

def abort
end

#add(page) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/embulk/output_redis.rb', line 33

def add(page)
  page.each do |record|
    hash = Hash[schema.names.zip(record)]
    puts "#{@message}: #{hash.to_json}"
    @redis.set(hash[task['key']], hash)
    @records += 1 
  end
end

#closeObject



30
31
# File 'lib/embulk/output_redis.rb', line 30

def close
end

#commitObject



48
49
50
51
52
53
# File 'lib/embulk/output_redis.rb', line 48

def commit
  commit_report = {
    "records" => @records
  }
  return commit_report
end

#finishObject



42
43
# File 'lib/embulk/output_redis.rb', line 42

def finish
end