Class: Momm::RedisStore
Constant Summary collapse
- DEFAULT_OPTIONS =
{ host: "localhost", port: 6379, namespace: "momm"}
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #client ⇒ Object
- #get_rate(currency, date = Date.today) ⇒ Object
-
#initialize(options = {}) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #set_rate(currency, rate, date = Date.today) ⇒ Object
Methods inherited from Storage
Constructor Details
#initialize(options = {}) ⇒ RedisStore
Returns a new instance of RedisStore.
7 8 9 |
# File 'lib/momm/redis_store.rb', line 7 def initialize( = {}) = DEFAULT_OPTIONS.dup.merge end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/momm/redis_store.rb', line 5 def end |
Instance Method Details
#client ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/momm/redis_store.rb', line 11 def client @client ||= begin ns = .delete(:namespace) require 'redis/namespace' native_client = Redis.new Redis::Namespace.new(ns, :redis => native_client) end end |
#get_rate(currency, date = Date.today) ⇒ Object
27 28 29 30 |
# File 'lib/momm/redis_store.rb', line 27 def get_rate(currency, date = Date.today) date = Date.parse(date) if date.is_a? String client.get("#{date}#{currency}").to_f end |
#set_rate(currency, rate, date = Date.today) ⇒ Object
22 23 24 25 |
# File 'lib/momm/redis_store.rb', line 22 def set_rate(currency, rate, date = Date.today) date = Date.parse(date) if date.is_a? String client.set "#{date}#{currency}", rate end |