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.
502 503 504 505 506 507 508 |
# File 'lib/redis_client.rb', line 502 def initialize(command_builder) @command_builder = command_builder @size = 0 @commands = [] @blocks = nil @retryable = true end |
Instance Method Details
#_blocks ⇒ Object
544 545 546 |
# File 'lib/redis_client.rb', line 544 def _blocks @blocks end |
#_coerce!(results) ⇒ Object
564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'lib/redis_client.rb', line 564 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
540 541 542 |
# File 'lib/redis_client.rb', line 540 def _commands @commands end |
#_empty? ⇒ Boolean
552 553 554 |
# File 'lib/redis_client.rb', line 552 def _empty? @commands.size <= 2 end |
#_retryable? ⇒ Boolean
560 561 562 |
# File 'lib/redis_client.rb', line 560 def _retryable? @retryable end |
#_size ⇒ Object
548 549 550 |
# File 'lib/redis_client.rb', line 548 def _size @commands.size end |
#_timeouts ⇒ Object
556 557 558 |
# File 'lib/redis_client.rb', line 556 def _timeouts nil end |
#call(*command, **kwargs, &block) ⇒ Object
510 511 512 513 514 515 |
# File 'lib/redis_client.rb', line 510 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
524 525 526 527 528 529 530 |
# File 'lib/redis_client.rb', line 524 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
532 533 534 535 536 537 538 |
# File 'lib/redis_client.rb', line 532 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
517 518 519 520 521 522 |
# File 'lib/redis_client.rb', line 517 def call_v(command, &block) command = @command_builder.generate(command) (@blocks ||= [])[@commands.size] = block if block_given? @commands << command nil end |