Class: Red
- Inherits:
-
Object
show all
- Defined in:
- lib/redness/red.rb
Defined Under Namespace
Classes: RedisUnavailable
Constant Summary
collapse
- REDIS_ERRORS =
[
RedisUnavailable,
Redis::CannotConnectError,
Redis::ConnectionError,
Redis::TimeoutError
]
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
49
50
51
52
|
# File 'lib/redness/red.rb', line 49
def method_missing(method, *args)
raise RedisUnavailable unless redis
redis.send(method, *args)
end
|
Class Attribute Details
.redis ⇒ Object
Returns the value of attribute redis.
14
15
16
|
# File 'lib/redness/red.rb', line 14
def redis
@redis
end
|
Class Method Details
.client_version ⇒ Object
17
18
19
|
# File 'lib/redness/red.rb', line 17
def self.client_version
@version ||= Redis::VERSION.scan(/\d+/).map { |s| s.to_i }
end
|
.delete(key) ⇒ Object
21
22
23
|
# File 'lib/redness/red.rb', line 21
def self.delete(key)
redis.del(key)
end
|
Instance Method Details
#execute_with_uncertainty(fail_return = []) ⇒ Object
29
30
31
32
33
|
# File 'lib/redness/red.rb', line 29
def execute_with_uncertainty(fail_return = [])
yield
rescue *REDIS_ERRORS
fail_return
end
|
#multi_with_caution(fail_return = [], &block) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/redness/red.rb', line 35
def multi_with_caution(fail_return = [], &block)
begin
redis.multi(&block) || fail_return
rescue Redis::TimeoutError
redis.discard raise
end
rescue
fail_return
end
|
#redis ⇒ Object
25
26
27
|
# File 'lib/redness/red.rb', line 25
def redis
Red.redis
end
|