Class: Embulk::InputRedis
- Inherits:
-
InputPlugin
- Object
- InputPlugin
- Embulk::InputRedis
- Defined in:
- lib/embulk/input_redis.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.transaction(config, &control) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/embulk/input_redis.rb', line 9 def self.transaction(config, &control) task = { 'host' => config.param('host', :string, :default => 'localhost'), 'port' => config.param('port', :integer, :default => 6379), 'db' => config.param('db', :integer, :default => 0), 'key_prefix' => config.param('key_prefix', :string, :default => ''), 'encode' => config.param('encode', :string, :default => 'json'), } threads = config.param('threads', :integer, 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
#run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/embulk/input_redis.rb', line 31 def run 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| # TODO: Use MGET or something case @task['encode'] when 'json' v = r.get(k) @page_builder.add([k, v]) end end @page_builder.finish # don't forget to call finish :-) commit_report = { } return commit_report end |