Class: HotPotato::Cache

Inherits:
Object
  • Object
show all
Includes:
Core
Defined in:
lib/hot_potato/cache.rb

Constant Summary

Constants included from Core

HotPotato::Core::CONFIG_PATH

Instance Method Summary collapse

Methods included from Core

#acquire_lock, #config, #log, #queue_inject, #queue_subscribe, #release_lock, #set_logger, #stat

Constructor Details

#initializeCache

Returns a new instance of Cache.



7
8
9
10
# File 'lib/hot_potato/cache.rb', line 7

def initialize
  log.info "Initializing connection to Redis (#{config['redis_hostname']}:#{config['redis_port']})"
  @@redis ||= Redis.new :host => config['redis_hostname'], :port => config['redis_port']
end

Instance Method Details

#del(k) ⇒ Object



31
32
33
# File 'lib/hot_potato/cache.rb', line 31

def del(k)
  @@redis.del(k)
end

#expire(k, ttl) ⇒ Object



35
36
37
# File 'lib/hot_potato/cache.rb', line 35

def expire(k, ttl)
  @@redis.expire(k, ttl)
end

#get(k) ⇒ Object



12
13
14
# File 'lib/hot_potato/cache.rb', line 12

def get(k)
  @@redis.get(k)
end

#getset(k, v) ⇒ Object



23
24
25
# File 'lib/hot_potato/cache.rb', line 23

def getset(k, v)
  @@redis.getset(k, v)
end

#incr(k) ⇒ Object



39
40
41
# File 'lib/hot_potato/cache.rb', line 39

def incr(k)
  @@redis.incr(k)
end

#keys(k) ⇒ Object



27
28
29
# File 'lib/hot_potato/cache.rb', line 27

def keys(k)
  @@redis.keys(k)
end

#set(k, v, ttl = nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/hot_potato/cache.rb', line 16

def set(k, v, ttl = nil)
  @@redis.multi do
    @@redis.set(k, v)
    @@redis.expire(k, ttl) if ttl
  end
end