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.
524 525 526 527 528 529 530 |
# File 'lib/redis_client.rb', line 524 def initialize(command_builder) @command_builder = command_builder @size = 0 @commands = [] @blocks = nil @retryable = true end |
Instance Method Details
#_blocks ⇒ Object
566 567 568 |
# File 'lib/redis_client.rb', line 566 def _blocks @blocks end |
#_coerce!(results) ⇒ Object
586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/redis_client.rb', line 586 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
562 563 564 |
# File 'lib/redis_client.rb', line 562 def _commands @commands end |
#_empty? ⇒ Boolean
574 575 576 |
# File 'lib/redis_client.rb', line 574 def _empty? @commands.size <= 2 end |
#_retryable? ⇒ Boolean
582 583 584 |
# File 'lib/redis_client.rb', line 582 def _retryable? @retryable end |
#_size ⇒ Object
570 571 572 |
# File 'lib/redis_client.rb', line 570 def _size @commands.size end |
#_timeouts ⇒ Object
578 579 580 |
# File 'lib/redis_client.rb', line 578 def _timeouts nil end |
#call(*command, **kwargs, &block) ⇒ Object
532 533 534 535 536 537 |
# File 'lib/redis_client.rb', line 532 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
546 547 548 549 550 551 552 |
# File 'lib/redis_client.rb', line 546 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
554 555 556 557 558 559 560 |
# File 'lib/redis_client.rb', line 554 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
539 540 541 542 543 544 |
# File 'lib/redis_client.rb', line 539 def call_v(command, &block) command = @command_builder.generate(command) (@blocks ||= [])[@commands.size] = block if block_given? @commands << command nil end |