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.



604
605
606
607
608
609
610
# File 'lib/redis_client.rb', line 604

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

Instance Method Details

#_blocksObject



646
647
648
# File 'lib/redis_client.rb', line 646

def _blocks
  @blocks
end

#_coerce!(results) ⇒ Object



666
667
668
669
670
671
672
673
674
675
676
677
678
679
# File 'lib/redis_client.rb', line 666

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



642
643
644
# File 'lib/redis_client.rb', line 642

def _commands
  @commands
end

#_empty?Boolean

Returns:

  • (Boolean)


654
655
656
# File 'lib/redis_client.rb', line 654

def _empty?
  @commands.size <= 2
end

#_retryable?Boolean

Returns:

  • (Boolean)


662
663
664
# File 'lib/redis_client.rb', line 662

def _retryable?
  @retryable
end

#_sizeObject



650
651
652
# File 'lib/redis_client.rb', line 650

def _size
  @commands.size
end

#_timeoutsObject



658
659
660
# File 'lib/redis_client.rb', line 658

def _timeouts
  nil
end

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



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

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



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

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



634
635
636
637
638
639
640
# File 'lib/redis_client.rb', line 634

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



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

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