Class: Cachetastic::Adapters::Redis

Inherits:
Base
  • Object
show all
Defined in:
lib/cachetastic/adapters/redis.rb

Instance Attribute Summary

Attributes inherited from Base

#klass

Instance Method Summary collapse

Methods inherited from Base

#debug?, #marshal, #unmarshal

Constructor Details

#initialize(klass) ⇒ Redis

Returns a new instance of Redis.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cachetastic/adapters/redis.rb', line 5

def initialize(klass)
  define_accessor(:redis_host)
  define_accessor(:redis_options)
  define_accessor(:delete_delay)
  self.redis_host ||= "redis://localhost:6379/"
  self.redis_options = ::Redis::Client::DEFAULTS.merge({
    db: "cachetastic",
    url: self.redis_host
  })
  super(klass)
  self.marshal_method = :yaml if self.marshal_method == :none
  connection
end

Instance Method Details

#delete(key) ⇒ Object

set



28
29
30
# File 'lib/cachetastic/adapters/redis.rb', line 28

def delete(key) # :nodoc:
  connection.del(transform_key(key))
end

#expire_allObject

delete



32
33
34
35
# File 'lib/cachetastic/adapters/redis.rb', line 32

def expire_all # :nodoc:
  connection.flushdb
  return nil
end

#get(key) ⇒ Object

:nodoc:



19
20
21
# File 'lib/cachetastic/adapters/redis.rb', line 19

def get(key) # :nodoc:
  connection.get(transform_key(key))
end

#set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) ⇒ Object

get



23
24
25
26
# File 'lib/cachetastic/adapters/redis.rb', line 23

def set(key, value, expiry_time = configatron.cachetastic.defaults.default_expiry) # :nodoc:
  connection.setex(transform_key(key), expiry_time, marshal(value))
  return value
end

#transform_key(key) ⇒ Object

expire_all



37
38
39
# File 'lib/cachetastic/adapters/redis.rb', line 37

def transform_key(key) # :nodoc:
  key.to_s.hexdigest
end

#valid?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/cachetastic/adapters/redis.rb', line 41

def valid?
  !connection.nil?
end