Class: Kredis::Types::Proxy
- Inherits:
-
Object
- Object
- Kredis::Types::Proxy
- Includes:
- Failsafe
- Defined in:
- lib/kredis/types/proxy.rb
Defined Under Namespace
Modules: Failsafe
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(redis, key, **options) ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(method, *args, **kwargs) ⇒ Object
- #multi(*args, **kwargs, &block) ⇒ Object
- #unwatch ⇒ Object
- #watch(&block) ⇒ Object
Methods included from Failsafe
#failsafe, #suppress_failsafe_with
Constructor Details
#initialize(redis, key, **options) ⇒ Proxy
Returns a new instance of Proxy.
11 12 13 14 |
# File 'lib/kredis/types/proxy.rb', line 11 def initialize(redis, key, **) @redis, @key = redis, key .each { |key, value| send("#{key}=", value) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/kredis/types/proxy.rb', line 35 def method_missing(method, *args, **kwargs) Kredis.instrument :proxy, **(method, *args, **kwargs) do failsafe do redis.public_send method, key, *args, **kwargs end end end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'lib/kredis/types/proxy.rb', line 7 def key @key end |
Instance Method Details
#multi(*args, **kwargs, &block) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/kredis/types/proxy.rb', line 16 def multi(*args, **kwargs, &block) redis.multi(*args, **kwargs) do |pipeline| self.pipeline = pipeline block.call ensure self.pipeline = nil end end |
#unwatch ⇒ Object
31 32 33 |
# File 'lib/kredis/types/proxy.rb', line 31 def unwatch redis.unwatch end |
#watch(&block) ⇒ Object
25 26 27 28 29 |
# File 'lib/kredis/types/proxy.rb', line 25 def watch(&block) redis.watch(key) do block.call end end |