Class: RedisClient::Multi

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

Direct Known Subclasses

Pipeline

Instance Method Summary collapse

Constructor Details

#initialize(command_builder) ⇒ Multi

Returns a new instance of Multi.



610
611
612
613
614
615
616
# File 'lib/redis_client.rb', line 610

def initialize(command_builder)
  @command_builder = command_builder
  @size = 0
  @commands = []
  @blocks = nil
  @retryable = true
end

Instance Method Details

#_blocksObject



652
653
654
# File 'lib/redis_client.rb', line 652

def _blocks
  @blocks
end

#_coerce!(results) ⇒ Object



672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/redis_client.rb', line 672

def _coerce!(results)
  results&.each_with_index do |result, index|
    if result.is_a?(CommandError)
      result._set_command(@commands[index + 1])
      raise result
    end

    if @blocks && block = @blocks[index + 1]
      results[index] = block.call(result)
    end
  end

  results
end

#_commandsObject



648
649
650
# File 'lib/redis_client.rb', line 648

def _commands
  @commands
end

#_empty?Boolean

Returns:

  • (Boolean)


660
661
662
# File 'lib/redis_client.rb', line 660

def _empty?
  @commands.size <= 2
end

#_retryable?Boolean

Returns:

  • (Boolean)


668
669
670
# File 'lib/redis_client.rb', line 668

def _retryable?
  @retryable
end

#_sizeObject



656
657
658
# File 'lib/redis_client.rb', line 656

def _size
  @commands.size
end

#_timeoutsObject



664
665
666
# File 'lib/redis_client.rb', line 664

def _timeouts
  nil
end

#call(*command, **kwargs, &block) ⇒ Object



618
619
620
621
622
623
# File 'lib/redis_client.rb', line 618

def call(*command, **kwargs, &block)
  command = @command_builder.generate(command, kwargs)
  (@blocks ||= [])[@commands.size] = block if block_given?
  @commands << command
  nil
end

#call_once(*command, **kwargs, &block) ⇒ Object



632
633
634
635
636
637
638
# File 'lib/redis_client.rb', line 632

def call_once(*command, **kwargs, &block)
  command = @command_builder.generate(command, kwargs)
  @retryable = false
  (@blocks ||= [])[@commands.size] = block if block_given?
  @commands << command
  nil
end

#call_once_v(command, &block) ⇒ Object



640
641
642
643
644
645
646
# File 'lib/redis_client.rb', line 640

def call_once_v(command, &block)
  command = @command_builder.generate(command)
  @retryable = false
  (@blocks ||= [])[@commands.size] = block if block_given?
  @commands << command
  nil
end

#call_v(command, &block) ⇒ Object



625
626
627
628
629
630
# File 'lib/redis_client.rb', line 625

def call_v(command, &block)
  command = @command_builder.generate(command)
  (@blocks ||= [])[@commands.size] = block if block_given?
  @commands << command
  nil
end