Sha256: 627fc1876656bd2ffbd57c5b0261d37af3df9efdaed75bf9ed3032e72b427421

Contents?: true

Size: 785 Bytes

Versions: 6

Compression:

Stored size: 785 Bytes

Contents

require 'redis'
require 'securerandom'

class CorrectHorseBatteryStaple::Writer::Redis < CorrectHorseBatteryStaple::Writer::Base

  include CorrectHorseBatteryStaple::Backend::Redis

  def initialize(dest, options={})
    super
    parse_uri(dest)
  end

  def write_corpus(corpus)
    create_database
    open_database

    # this is faster and atomic (for some ops), but it doesn't allow RMW cycles
    db.multi do
      save_entries(corpus)
      save_stats(corpus.stats)
    end
  rescue
    logger.error "error in Redis write_corpus: #{$!.inspect}"
    raise
  ensure
    close_database
  end

  protected

  def save_entries(corpus)
    size = corpus.size
    corpus.each_with_index do |w, index|
      add_word(w, index)
    end
    db.set(@id_key, size-1)
  ensure
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
correct-horse-battery-staple-0.6.6 lib/correct_horse_battery_staple/writer/redis.rb
correct-horse-battery-staple-0.6.5 lib/correct_horse_battery_staple/writer/redis.rb
correct-horse-battery-staple-0.6.4 lib/correct_horse_battery_staple/writer/redis.rb
correct-horse-battery-staple-0.6.3 lib/correct_horse_battery_staple/writer/redis.rb
correct-horse-battery-staple-0.6.2 lib/correct_horse_battery_staple/writer/redis.rb
correct-horse-battery-staple-0.6.1 lib/correct_horse_battery_staple/writer/redis.rb