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.
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
#_blocks ⇒ Object
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 |
#_commands ⇒ Object
642 643 644 |
# File 'lib/redis_client.rb', line 642 def _commands @commands end |
#_empty? ⇒ Boolean
654 655 656 |
# File 'lib/redis_client.rb', line 654 def _empty? @commands.size <= 2 end |
#_retryable? ⇒ Boolean
662 663 664 |
# File 'lib/redis_client.rb', line 662 def _retryable? @retryable end |
#_size ⇒ Object
650 651 652 |
# File 'lib/redis_client.rb', line 650 def _size @commands.size end |
#_timeouts ⇒ Object
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 |