Class: RedisClient::Cluster::Transaction
- Inherits:
-
Object
- Object
- RedisClient::Cluster::Transaction
- Defined in:
- lib/redis_client/cluster/transaction.rb
Constant Summary collapse
- ConsistencyError =
Class.new(::RedisClient::Error)
- MAX_REDIRECTION =
2
Instance Method Summary collapse
- #call(*command, **kwargs, &block) ⇒ Object
- #call_once(*command, **kwargs, &block) ⇒ Object
- #call_once_v(command, &block) ⇒ Object
- #call_v(command, &block) ⇒ Object
- #execute ⇒ Object
-
#initialize(router, command_builder, node: nil, slot: nil) ⇒ Transaction
constructor
A new instance of Transaction.
Constructor Details
#initialize(router, command_builder, node: nil, slot: nil) ⇒ Transaction
Returns a new instance of Transaction.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/redis_client/cluster/transaction.rb', line 12 def initialize(router, command_builder, node: nil, slot: nil) @router = router @command_builder = command_builder @retryable = true @pipeline = ::RedisClient::Pipeline.new(@command_builder) @pending_commands = [] @node = node prepare_tx unless @node.nil? @watching_slot = slot end |
Instance Method Details
#call(*command, **kwargs, &block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/redis_client/cluster/transaction.rb', line 23 def call(*command, **kwargs, &block) command = @command_builder.generate(command, kwargs) if prepare(command) @pipeline.call_v(command, &block) else defer { @pipeline.call_v(command, &block) } end end |
#call_once(*command, **kwargs, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/redis_client/cluster/transaction.rb', line 41 def call_once(*command, **kwargs, &block) @retryable = false command = @command_builder.generate(command, kwargs) if prepare(command) @pipeline.call_once_v(command, &block) else defer { @pipeline.call_once_v(command, &block) } end end |
#call_once_v(command, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/redis_client/cluster/transaction.rb', line 51 def call_once_v(command, &block) @retryable = false command = @command_builder.generate(command) if prepare(command) @pipeline.call_once_v(command, &block) else defer { @pipeline.call_once_v(command, &block) } end end |
#call_v(command, &block) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/redis_client/cluster/transaction.rb', line 32 def call_v(command, &block) command = @command_builder.generate(command) if prepare(command) @pipeline.call_v(command, &block) else defer { @pipeline.call_v(command, &block) } end end |
#execute ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/redis_client/cluster/transaction.rb', line 61 def execute @pending_commands.each(&:call) raise ArgumentError, 'empty transaction' if @pipeline._empty? raise ConsistencyError, "couldn't determine the node: #{@pipeline._commands}" if @node.nil? settle end |