Class: StuffClassifier::RedisStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/stuff-classifier/storage.rb

Instance Attribute Summary

Attributes inherited from Storage

#storage

Instance Method Summary collapse

Methods inherited from Storage

#classifier_to_storage, #clear_storage, #storage_to_classifier

Constructor Details

#initialize(key, redis_options = nil) ⇒ RedisStorage

Returns a new instance of RedisStorage.



92
93
94
95
96
# File 'lib/stuff-classifier/storage.rb', line 92

def initialize(key, redis_options=nil)
  super
  @key = key
  @redis = Redis.new(redis_options || {})
end

Instance Method Details

#load_state(classifier) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/stuff-classifier/storage.rb', line 98

def load_state(classifier)
  if @storage.length == 0 && @redis.exists(@key)
    data = @redis.get(@key)
    @storage = Marshal.load(data)
  end
  storage_to_classifier(classifier)
end

#purge_state(classifier) ⇒ Object



111
112
113
114
# File 'lib/stuff-classifier/storage.rb', line 111

def purge_state(classifier)
  clear_storage(classifier)
  _write_to_redis
end

#save_state(classifier) ⇒ Object



106
107
108
109
# File 'lib/stuff-classifier/storage.rb', line 106

def save_state(classifier)
  classifier_to_storage(classifier)
  _write_to_redis
end