Class: Renderful::Cache::Redis
- Defined in:
- lib/renderful/cache/redis.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
- #delete(*keys) ⇒ Object
- #delete_matched(pattern) ⇒ Object
- #exist?(key) ⇒ Boolean
- #fetch(key) ⇒ Object
-
#initialize(redis) ⇒ Redis
constructor
A new instance of Redis.
- #read(key) ⇒ Object
- #write(key, value) ⇒ Object
Constructor Details
#initialize(redis) ⇒ Redis
Returns a new instance of Redis.
8 9 10 |
# File 'lib/renderful/cache/redis.rb', line 8 def initialize(redis) @redis = redis end |
Instance Attribute Details
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
6 7 8 |
# File 'lib/renderful/cache/redis.rb', line 6 def redis @redis end |
Instance Method Details
#delete(*keys) ⇒ Object
24 25 26 |
# File 'lib/renderful/cache/redis.rb', line 24 def delete(*keys) redis.del(*keys) end |
#delete_matched(pattern) ⇒ Object
28 29 30 31 |
# File 'lib/renderful/cache/redis.rb', line 28 def delete_matched(pattern) keys = redis.scan_each(match: pattern).to_a delete(*keys) end |
#exist?(key) ⇒ Boolean
12 13 14 |
# File 'lib/renderful/cache/redis.rb', line 12 def exist?(key) redis.exists(key) end |
#fetch(key) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/renderful/cache/redis.rb', line 33 def fetch(key) return read(key) if exist?(key) yield.tap do |value| write(key, value) end end |
#read(key) ⇒ Object
16 17 18 |
# File 'lib/renderful/cache/redis.rb', line 16 def read(key) redis.get(key) end |
#write(key, value) ⇒ Object
20 21 22 |
# File 'lib/renderful/cache/redis.rb', line 20 def write(key, value) redis.set(key, value) end |