Class: MultiRedis::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_redis/operation.rb

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

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 options = {}, &block

  @target = options[:target] || self
  @redis = options[:redis]
  @steps = []

  configure &block if block
end

Instance Attribute Details

#futureObject (readonly)

Returns the value of attribute future


5
6
7
# File 'lib/multi_redis/operation.rb', line 5

def future
  @future
end

#redisObject

Returns the value of attribute redis


4
5
6
# File 'lib/multi_redis/operation.rb', line 4

def redis
  @redis
end

#stepsObject (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

Raises:

  • (ArgumentError)

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