Class: Moneta::Adapters::Redis
- Inherits:
-
Object
- Object
- Moneta::Adapters::Redis
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/redis.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ Redis
constructor
A new instance of Redis.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ Redis
Returns a new instance of Redis.
13 14 15 |
# File 'lib/moneta/adapters/redis.rb', line 13 def initialize( = {}) @cache = ::Redis.new() end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 |
# File 'lib/moneta/adapters/redis.rb', line 21 def [](key) deserialize(@cache.get(key_for(key))) end |
#clear ⇒ Object
36 37 38 |
# File 'lib/moneta/adapters/redis.rb', line 36 def clear(*) @cache.flushdb end |
#delete(key) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/moneta/adapters/redis.rb', line 25 def delete(key, *) string_key = key_for(key) value = self[key] @cache.del(string_key) if value value end |
#key?(key) ⇒ Boolean
17 18 19 |
# File 'lib/moneta/adapters/redis.rb', line 17 def key?(key, *) !@cache[key_for(key)].nil? end |
#store(key, value) ⇒ Object
32 33 34 |
# File 'lib/moneta/adapters/redis.rb', line 32 def store(key, value, *) @cache.set(key_for(key), serialize(value)) end |