Class: Wrest::Caching::Redis
- Inherits:
-
Object
- Object
- Wrest::Caching::Redis
- Defined in:
- lib/wrest/caching/redis.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, response) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(redis_options = {}) ⇒ Redis
constructor
A new instance of Redis.
Constructor Details
#initialize(redis_options = {}) ⇒ Redis
Returns a new instance of Redis.
14 15 16 |
# File 'lib/wrest/caching/redis.rb', line 14 def initialize( = {}) @redis = ::Redis.new() end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 21 22 |
# File 'lib/wrest/caching/redis.rb', line 18 def [](key) value = @redis.get(key) unmarshalled_value = value.nil? ? nil : YAML::load(value) unmarshalled_value end |
#[]=(key, response) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/wrest/caching/redis.rb', line 24 def []=(key, response) marshalled_response = YAML::dump(response) @redis.set(key, marshalled_response) unless response.expired? @redis.expire(key, response.freshness_lifetime) end end |
#delete(key) ⇒ Object
32 33 34 35 36 |
# File 'lib/wrest/caching/redis.rb', line 32 def delete(key) value = self[key] @redis.del(key) return value end |