Class: Moneta::Redis

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

Instance Method Summary collapse

Methods included from Defaults

#fetch

Constructor Details

#initialize(options = {}) ⇒ Redis

Returns a new instance of Redis.



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

def initialize(options = {})
  @cache = ::Redis.new(options)
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/moneta/redis.rb', line 22

def [](key)
  @cache.get(key)
end

#[]=(key, value) ⇒ Object



26
27
28
# File 'lib/moneta/redis.rb', line 26

def []=(key, value)
  store(key, value)
end

#clearObject



45
46
47
# File 'lib/moneta/redis.rb', line 45

def clear
  @cache.flush_db
end

#delete(key) ⇒ Object



30
31
32
33
34
# File 'lib/moneta/redis.rb', line 30

def delete(key)
  value = @cache[key]
  @cache.delete(key) if value
  value
end

#key?(key) ⇒ Boolean Also known as: has_key?

Returns:

  • (Boolean)


16
17
18
# File 'lib/moneta/redis.rb', line 16

def key?(key)
  !@cache[key].nil?
end

#store(key, value, options = {}) ⇒ Object



36
37
38
# File 'lib/moneta/redis.rb', line 36

def store(key, value, options = {})
  @cache.set(key, value, options[:expires_in])
end

#update_key(key, options = {}) ⇒ Object



40
41
42
43
# File 'lib/moneta/redis.rb', line 40

def update_key(key, options = {})
  val = @cache[key]
  self.store(key, val, options)
end