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.



584
585
586
587
588
589
590
# File 'lib/redis_client.rb', line 584

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

Instance Method Details

#_blocksObject



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

def _blocks
  @blocks
end

#_coerce!(results) ⇒ Object



646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/redis_client.rb', line 646

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



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

def _commands
  @commands
end

#_empty?Boolean

Returns:

  • (Boolean)


634
635
636
# File 'lib/redis_client.rb', line 634

def _empty?
  @commands.size <= 2
end

#_retryable?Boolean

Returns:

  • (Boolean)


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

def _retryable?
  @retryable
end

#_sizeObject



630
631
632
# File 'lib/redis_client.rb', line 630

def _size
  @commands.size
end

#_timeoutsObject



638
639
640
# File 'lib/redis_client.rb', line 638

def _timeouts
  nil
end

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



592
593
594
595
596
597
# File 'lib/redis_client.rb', line 592

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



606
607
608
609
610
611
612
# File 'lib/redis_client.rb', line 606

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



614
615
616
617
618
619
620
# File 'lib/redis_client.rb', line 614

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



599
600
601
602
603
604
# File 'lib/redis_client.rb', line 599

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