Class: Enum::RedisStore

Inherits:
Object
  • Object
show all
Defined in:
lib/enum/store/redis_store.rb

Defined Under Namespace

Modules: Getter, Setter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis = nil) ⇒ RedisStore

Returns a new instance of RedisStore.



8
9
10
# File 'lib/enum/store/redis_store.rb', line 8

def initialize(redis = nil)
  @connection = redis || Redis::Namespace.new(:enum, redis: Redis.new)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/enum/store/redis_store.rb', line 6

def connection
  @connection
end

Instance Method Details

#get_value(key) ⇒ Object



12
13
14
# File 'lib/enum/store/redis_store.rb', line 12

def get_value(key)
  Getter.get_value(connection, key)
end

#load_hash(hash) ⇒ Object



25
26
27
28
29
# File 'lib/enum/store/redis_store.rb', line 25

def load_hash(hash)
  hash.each_pair do |key, value|
    Setter.set_value(connection, key, value)
  end
end

#load_yaml(file) ⇒ Object



20
21
22
23
# File 'lib/enum/store/redis_store.rb', line 20

def load_yaml(file)
  require 'yaml'
  load_hash(YAML.load_file(file))
end

#set_value(key, value) ⇒ Object



16
17
18
# File 'lib/enum/store/redis_store.rb', line 16

def set_value(key, value)
  Setter.set_value(connection, key, value)
end