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, watch) ⇒ Transaction
constructor
A new instance of Transaction.
Constructor Details
#initialize(router, command_builder, watch) ⇒ Transaction
12 13 14 15 16 17 18 19 20 |
# File 'lib/redis_client/cluster/transaction.rb', line 12 def initialize(router, command_builder, watch) @router = router @command_builder = command_builder @watch = watch @retryable = true @pipeline = ::RedisClient::Pipeline.new(@command_builder) @buffer = [] @node = nil end |
Instance Method Details
#call(*command, **kwargs, &block) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/redis_client/cluster/transaction.rb', line 22 def call(*command, **kwargs, &block) command = @command_builder.generate(command, kwargs) if prepare(command) @pipeline.call_v(command, &block) else @buffer << -> { @pipeline.call_v(command, &block) } end end |
#call_once(*command, **kwargs, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/redis_client/cluster/transaction.rb', line 40 def call_once(*command, **kwargs, &block) @retryable = false command = @command_builder.generate(command, kwargs) if prepare(command) @pipeline.call_once_v(command, &block) else @buffer << -> { @pipeline.call_once_v(command, &block) } end end |
#call_once_v(command, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/redis_client/cluster/transaction.rb', line 50 def call_once_v(command, &block) @retryable = false command = @command_builder.generate(command) if prepare(command) @pipeline.call_once_v(command, &block) else @buffer << -> { @pipeline.call_once_v(command, &block) } end end |
#call_v(command, &block) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/redis_client/cluster/transaction.rb', line 31 def call_v(command, &block) command = @command_builder.generate(command) if prepare(command) @pipeline.call_v(command, &block) else @buffer << -> { @pipeline.call_v(command, &block) } end end |
#execute ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/redis_client/cluster/transaction.rb', line 60 def execute @buffer.each(&:call) raise ArgumentError, 'empty transaction' if @pipeline._empty? raise ConsistencyError, "couldn't determine the node: #{@pipeline._commands}" if @node.nil? raise ConsistencyError, "unsafe watch: #{@watch.join(' ')}" unless safe_watch? settle end |