Class: Juno::Adapters::Redis
- Inherits:
-
Base
- Object
- Base
- Juno::Adapters::Redis
show all
- Defined in:
- lib/juno/adapters/redis.rb
Overview
Instance Method Summary
collapse
Methods inherited from Base
#[], #[]=, #close, #fetch
Constructor Details
#initialize(options = {}) ⇒ Redis
11
12
13
|
# File 'lib/juno/adapters/redis.rb', line 11
def initialize(options = {})
@redis = ::Redis.new(options)
end
|
Instance Method Details
#clear(options = {}) ⇒ Object
43
44
45
46
|
# File 'lib/juno/adapters/redis.rb', line 43
def clear(options = {})
@redis.flushdb
self
end
|
#delete(key, options = {}) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/juno/adapters/redis.rb', line 27
def delete(key, options = {})
if value = load(key, options)
@redis.del(key)
value
end
end
|
#key?(key, options = {}) ⇒ Boolean
15
16
17
|
# File 'lib/juno/adapters/redis.rb', line 15
def key?(key, options = {})
@redis.exists(key)
end
|
#load(key, options = {}) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/juno/adapters/redis.rb', line 19
def load(key, options = {})
value = @redis.get(key)
if value && (expires = options[:expires])
@redis.expire(key, expires)
end
value
end
|
#store(key, value, options = {}) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/juno/adapters/redis.rb', line 34
def store(key, value, options = {})
if expires = options[:expires]
@redis.setex(key, expires, value)
else
@redis.set(key, value)
end
value
end
|