Class: Embulk::InputRedis

Inherits:
InputPlugin
  • Object
show all
Defined in:
lib/embulk/input_redis.rb

Class Method Summary collapse

Class Method Details

.run(task, schema, index, page_builder) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/embulk/input_redis.rb', line 29

def self.run(task, schema, index, page_builder)
  puts "Redis input thread #{index}..."

  r = ::Redis.new(:host => task['host'], :port => task['port'], :db => task['db'])
  r.keys("#{task['key_prefix']}*").each do |k|
    page_builder.add([k, r.get(k)])
  end
  page_builder.finish  # don't forget to call finish :-)

  commit_report = {
  }
  return commit_report
end

.transaction(config, &control) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/embulk/input_redis.rb', line 8

def self.transaction(config, &control)
  task = {
    'host' => config.param('host', :string, :default => 'localhost'),
    'port' => config.param('port', :int, :default => 6379),
    'db' => config.param('db', :int, :default => 0),
    'key_prefix' => config.param('key_prefix', :string, :default => ''),
  }
  threads = config.param('threads', :int, default: 1)

  columns = [
    Column.new(0, 'key', :string),
    Column.new(1, 'value', :string),
  ]

  puts "Redis input started."
  commit_reports = yield(task, columns, threads)
  puts "Redis input finished. Commit reports = #{commit_reports.to_json}"

  return {}
end