class MultiRedis::Operation

Constants

TYPES

Attributes

future[R]
redis[RW]
steps[R]

Public Class Methods

new(options = {}) click to toggle source
# 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

Public Instance Methods

add(type, &block) click to toggle source
# 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) click to toggle source
# File lib/multi_redis/operation.rb, line 16
def configure &block
  DSL.new(self).instance_eval &block
end
execute(*args) click to toggle source
# 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