Class: CacheReduce::CacheStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_reduce.rb

Instance Method Summary collapse

Instance Method Details

#read(keys) ⇒ Object

TODO update interface key, period, hours



101
102
103
104
105
106
107
108
109
110
# File 'lib/cache_reduce.rb', line 101

def read(keys)
  # puts "READ: #{keys}"
  values = {}
  redis.mget(*keys).each_with_index do |value, i|
    key = keys[i]
    value = redis.get(key)
    values[key] = value ? JSON.parse("[" + value + "]")[0] : nil
  end
  values
end

#redisObject



117
118
119
# File 'lib/cache_reduce.rb', line 117

def redis
  @redis ||= Redis.new
end

#write(key, value) ⇒ Object



112
113
114
115
# File 'lib/cache_reduce.rb', line 112

def write(key, value)
  # puts "WRITE: #{key} #{value}"
  redis.set(key, value.to_json)
end