Class: Embulk::InputRedis

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.transaction(config, &control) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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 => ''),
    'url' => config.param('url', :string),
  }
  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

Instance Method Details

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/embulk/input/redis.rb', line 30

def run
  puts "Redis input thread #{@index}..."

  if @task['url'].nil? || @task['url'].empty?
    r = ::Redis.new(:host => @task['host'], :port => @task['port'], :db => @task['db'])
  else
    r = ::Redis.new(:url => @task['url'])
  end
  
  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