Class: RedisBuddy::CacheStore

Inherits:
ActiveSupport::Cache::Store
  • Object
show all
Defined in:
lib/redis_buddy/cache_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(*adresses) ⇒ CacheStore

Returns a new instance of CacheStore.



3
4
5
6
7
8
9
# File 'lib/redis_buddy/cache_store.rb', line 3

def initialize(*adresses)
  options = adresses.extract_options!
  ns = options.delete(:redis_namespace) || Rails.application.class.to_s.split('::').first.downcase
  @r = RedisFactory.create(adresses)
  @client = Redis::Namespace.new(ns, :redis => @r)
  super options
end

Instance Method Details

#clearObject



57
58
59
# File 'lib/redis_buddy/cache_store.rb', line 57

def clear
  @client.flushdb
end

#clientObject



70
71
72
# File 'lib/redis_buddy/cache_store.rb', line 70

def client
  @client
end

#decrement(key, amount = nil) ⇒ Object



29
30
31
# File 'lib/redis_buddy/cache_store.rb', line 29

def decrement(key, amount = nil)
  amount.nil? ? @client.decr(key) : @client.decrby(key, amount)
end

#delete_matched(matcher, options = nil) ⇒ Object



33
34
35
# File 'lib/redis_buddy/cache_store.rb', line 33

def delete_matched(matcher, options = nil)
  delete keys(matcher)
end

#exipire_at(key, time) ⇒ Object



41
42
43
# File 'lib/redis_buddy/cache_store.rb', line 41

def exipire_at(key, time)
  @client.exipireat(key, time)
end

#exist?(key) ⇒ Boolean Also known as: exists?

Returns:

  • (Boolean)


20
21
22
# File 'lib/redis_buddy/cache_store.rb', line 20

def exist?(key)
  @client.exists(key)
end

#expire_in(key, ttl) ⇒ Object



37
38
39
# File 'lib/redis_buddy/cache_store.rb', line 37

def expire_in(key, ttl)
  @client.expire(key, ttl)
end

#increment(key, amount = nil) ⇒ Object



25
26
27
# File 'lib/redis_buddy/cache_store.rb', line 25

def increment(key, amount = nil)
  amount.nil? ? @client.incr(key) : @client.incrby(key, amount)
end

#infoObject



61
62
63
# File 'lib/redis_buddy/cache_store.rb', line 61

def info
  @client.info
end

#keys(matcher = "*", options = nil) ⇒ Object



65
66
67
68
# File 'lib/redis_buddy/cache_store.rb', line 65

def keys(matcher = "*", options = nil)
  options = merged_options(options)
  @client.keys namespaced_key(matcher, options)
end

#length(key) ⇒ Object



45
46
47
# File 'lib/redis_buddy/cache_store.rb', line 45

def length(key)
  @client.llen(key)
end

#pop(key) ⇒ Object



15
16
17
18
# File 'lib/redis_buddy/cache_store.rb', line 15

def pop(key)
  value = @client.rpop(key)
  value ? decode(value) : nil
end

#push(key, value) ⇒ Object



11
12
13
# File 'lib/redis_buddy/cache_store.rb', line 11

def push(key, value)
  @client.lpush(key, encode(value))
end

#ttl(key) ⇒ Object



49
50
51
# File 'lib/redis_buddy/cache_store.rb', line 49

def ttl(key)
  @client.ttl(key)
end

#type(key) ⇒ Object



53
54
55
# File 'lib/redis_buddy/cache_store.rb', line 53

def type(key)
  @client.type(key)
end