Class: RedisClient::Multi
- Inherits:
-
Object
- Object
- RedisClient::Multi
- Defined in:
- lib/redis_client.rb
Direct Known Subclasses
Instance Method Summary collapse
- #_blocks ⇒ Object
- #_coerce!(results) ⇒ Object
- #_commands ⇒ Object
- #_empty? ⇒ Boolean
- #_retryable? ⇒ Boolean
- #_size ⇒ Object
- #_timeouts ⇒ Object
- #call(*command, **kwargs, &block) ⇒ Object
- #call_once(*command, **kwargs, &block) ⇒ Object
- #call_once_v(command, &block) ⇒ Object
- #call_v(command, &block) ⇒ Object
-
#initialize(command_builder) ⇒ Multi
constructor
A new instance of Multi.
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
#_blocks ⇒ Object
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 |
#_commands ⇒ Object
648 649 650 |
# File 'lib/redis_client.rb', line 648 def _commands @commands end |
#_empty? ⇒ Boolean
660 661 662 |
# File 'lib/redis_client.rb', line 660 def _empty? @commands.size <= 2 end |
#_retryable? ⇒ Boolean
668 669 670 |
# File 'lib/redis_client.rb', line 668 def _retryable? @retryable end |
#_size ⇒ Object
656 657 658 |
# File 'lib/redis_client.rb', line 656 def _size @commands.size end |
#_timeouts ⇒ Object
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 |