Class: RedisBuddy::CacheStore
- Inherits:
-
ActiveSupport::Cache::Store
- Object
- ActiveSupport::Cache::Store
- RedisBuddy::CacheStore
- Defined in:
- lib/redis_buddy/cache_store.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #client ⇒ Object
- #decrement(key, amount = nil) ⇒ Object
- #delete_matched(matcher, options = nil) ⇒ Object
- #exipire_at(key, time) ⇒ Object
- #exist?(key) ⇒ Boolean (also: #exists?)
- #expire_in(key, ttl) ⇒ Object
- #increment(key, amount = nil) ⇒ Object
- #info ⇒ Object
-
#initialize(*adresses) ⇒ CacheStore
constructor
A new instance of CacheStore.
- #keys(matcher = "*", options = nil) ⇒ Object
- #length(key) ⇒ Object
- #pop(key) ⇒ Object
- #push(key, value) ⇒ Object
- #ttl(key) ⇒ Object
- #type(key) ⇒ Object
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) = adresses. ns = .delete(:redis_namespace) || Rails.application.class.to_s.split('::').first.downcase @r = RedisFactory.create(adresses) @client = Redis::Namespace.new(ns, :redis => @r) super end |
Instance Method Details
#clear ⇒ Object
57 58 59 |
# File 'lib/redis_buddy/cache_store.rb', line 57 def clear @client.flushdb end |
#client ⇒ Object
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, = 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?
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 |
#info ⇒ Object
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 = "*", = nil) = () @client.keys namespaced_key(matcher, ) 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 |