Module: Razoul::Persistence::Redis

Defined in:
lib/razoul/persistence/redis.rb

Constant Summary collapse

HOST =
'127.0.0.1'
PORT =
6379
DB =
0

Class Method Summary collapse

Class Method Details

.configure(class_name, config) ⇒ Object



10
11
12
# File 'lib/razoul/persistence/redis.rb', line 10

def configure(class_name, config)
  class_name.new(hash_config_attrs(config))
end

.find(conn, key) ⇒ Object



18
19
20
# File 'lib/razoul/persistence/redis.rb', line 18

def find(conn, key)
  conn.get(key)
end

.hash_config_attrs(config) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/razoul/persistence/redis.rb', line 22

def hash_config_attrs(config)
  hash = {}
  constants.map do |const|
    value =  config.has_attr?("#{self.class.name}_#{const.downcase}") ?
      config.send("#{self.class.name}_#{const.downcase}") : const_get(const)
    hash.merge!(const.downcase.to_sym =>  value)
  end
  hash
end

.save(conn, key, value) ⇒ Object



14
15
16
# File 'lib/razoul/persistence/redis.rb', line 14

def save(conn, key, value)
  conn.set(key, value).eql?('OK') ? true : false
end