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.
16 17 18 |
# File 'lib/wrest/caching/redis.rb', line 16 def initialize( = {}) @redis = ::Redis.new() end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 23 |
# File 'lib/wrest/caching/redis.rb', line 20 def [](key) value = @redis.get(key) value.nil? ? nil : YAML.unsafe_load(value) end |
#[]=(key, response) ⇒ Object
25 26 27 28 29 |
# File 'lib/wrest/caching/redis.rb', line 25 def []=(key, response) marshalled_response = YAML.dump(response) @redis.set(key, marshalled_response) @redis.expire(key, response.freshness_lifetime) unless response.expired? end |
#delete(key) ⇒ Object
31 32 33 34 35 |
# File 'lib/wrest/caching/redis.rb', line 31 def delete(key) value = self[key] @redis.del(key) value end |