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)
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, asking: false) ⇒ Transaction
constructor
A new instance of Transaction.
Constructor Details
#initialize(router, command_builder, node: nil, slot: nil, asking: false) ⇒ Transaction
Returns a new instance of Transaction.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/redis_client/cluster/transaction.rb', line 16 def initialize(router, command_builder, node: nil, slot: nil, asking: false) @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 @asking = asking end |
Instance Method Details
#call(*command, **kwargs, &block) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/redis_client/cluster/transaction.rb', line 28 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
46 47 48 49 50 51 52 53 54 |
# File 'lib/redis_client/cluster/transaction.rb', line 46 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
56 57 58 59 60 61 62 63 64 |
# File 'lib/redis_client/cluster/transaction.rb', line 56 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
37 38 39 40 41 42 43 44 |
# File 'lib/redis_client/cluster/transaction.rb', line 37 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
66 67 68 69 70 71 72 73 |
# File 'lib/redis_client/cluster/transaction.rb', line 66 def execute @pending_commands.each(&:call) return EMPTY_ARRAY if @pipeline._empty? raise ConsistencyError, "couldn't determine the node: #{@pipeline._commands}" if @node.nil? commit end |