Class: CorrectHorseBatteryStaple::Writer::Redis

Inherits:
Base show all
Includes:
Backend::Redis
Defined in:
lib/correct_horse_battery_staple/writer/redis.rb

Instance Attribute Summary

Attributes inherited from Base

#dest, #options

Instance Method Summary collapse

Methods included from Backend::Redis

included

Methods inherited from Base

#close

Methods included from Common

#array_sample, #logger, #random_in_range, #random_number, #set_sample

Methods inherited from CorrectHorseBatteryStaple::Writer

make_writer, write

Constructor Details

#initialize(dest, options = {}) ⇒ Redis

Returns a new instance of Redis.



8
9
10
11
# File 'lib/correct_horse_battery_staple/writer/redis.rb', line 8

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

Instance Method Details

#write_corpus(corpus) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/correct_horse_battery_staple/writer/redis.rb', line 13

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