class Embulk::OutputRedis

Public Class Methods

new(task, schema, index) click to toggle source
Calls superclass method
# File lib/embulk/output/redis.rb, line 26
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
transaction(config, schema, processor_count) { |task| ... } click to toggle source
# 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),
    'expire' => config.param('expire', :integer, :default => -1),
  }

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

  return {}
end

Public Instance Methods

abort() click to toggle source
# File lib/embulk/output/redis.rb, line 66
def abort
end
add(page) click to toggle source
# File lib/embulk/output/redis.rb, line 40
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)
      if task['expire'] > -1
        @redis.expire(record[0][task['key']], task['expire'])
      end
    else
      @redis.set(hash[task['key']], hash)
      if task['expire'] > -1
        @redis.expire(hash[task['key']], task['expire'])
      end
    end

    @records += 1 
  end
end
close() click to toggle source
# File lib/embulk/output/redis.rb, line 37
def close
end
commit() click to toggle source
# File lib/embulk/output/redis.rb, line 69
def commit
  commit_report = {
    "records" => @records
  }
  return commit_report
end
finish() click to toggle source
# File lib/embulk/output/redis.rb, line 63
def finish
end