Class: MultiRedis::Operation
- Inherits:
-
Object
- Object
- MultiRedis::Operation
- Defined in:
- lib/multi_redis/operation.rb
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#future ⇒ Object
readonly
Returns the value of attribute future.
-
#redis ⇒ Object
Returns the value of attribute redis.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #add(type, &block) ⇒ Object
- #configure(&block) ⇒ Object
- #execute(*args) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Operation
constructor
A new instance of Operation.
Constructor Details
#initialize(options = {}, &block) ⇒ Operation
Returns a new instance of Operation.
7 8 9 10 11 12 13 14 |
# File 'lib/multi_redis/operation.rb', line 7 def initialize = {}, &block @target = [:target] || self @redis = [:redis] @steps = [] configure &block if block end |
Instance Attribute Details
#future ⇒ Object (readonly)
Returns the value of attribute future.
5 6 7 |
# File 'lib/multi_redis/operation.rb', line 5 def future @future end |
#redis ⇒ Object
Returns the value of attribute redis.
4 5 6 |
# File 'lib/multi_redis/operation.rb', line 4 def redis @redis end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
5 6 7 |
# File 'lib/multi_redis/operation.rb', line 5 def steps @steps end |
Instance Method Details
#add(type, &block) ⇒ Object
33 34 35 36 |
# File 'lib/multi_redis/operation.rb', line 33 def add type, &block raise ArgumentError, "Unknown type #{type}, must be one of #{TYPES.join ', '}." unless TYPES.include? type @steps << Step.new(@target, type, block) end |
#configure(&block) ⇒ Object
16 17 18 |
# File 'lib/multi_redis/operation.rb', line 16 def configure &block DSL.new(self).instance_eval &block end |
#execute(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/multi_redis/operation.rb', line 20 def execute *args if MultiRedis.executing? MultiRedis.executor.add self, *args @future = Future.new else e = Executor.new redis: @redis e.add self, *args e.execute.first.tap do |result| @future = Future.new result end end end |