Class: Moneta::Adapters::Redis

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/moneta/adapters/redis.rb

Instance Method Summary collapse

Methods included from Defaults

#[]=, #fetch

Constructor Details

#initialize(options = {}) ⇒ Redis

Returns a new instance of Redis.



13
14
15
# File 'lib/moneta/adapters/redis.rb', line 13

def initialize(options = {})
  @cache = ::Redis.new(options)
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

#clearObject



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

Returns:

  • (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