Class: Redis::Cluster::TransactionAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/cluster/transaction_adapter.rb

Defined Under Namespace

Classes: Internal

Instance Method Summary collapse

Constructor Details

#initialize(client, router, command_builder, node: nil, slot: nil, asking: false) ⇒ TransactionAdapter

Returns a new instance of TransactionAdapter.



49
50
51
52
53
54
55
56
57
# File 'lib/redis/cluster/transaction_adapter.rb', line 49

def initialize(client, router, command_builder, node: nil, slot: nil, asking: false)
  @client = client
  @router = router
  @command_builder = command_builder
  @node = node
  @slot = slot
  @asking = asking
  @lock_released = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object (private)



91
92
93
94
95
# File 'lib/redis/cluster/transaction_adapter.rb', line 91

def method_missing(name, *args, **kwargs, &block)
  return @client.public_send(name, *args, **kwargs, &block) if @client.respond_to?(name)

  super
end

Instance Method Details

#discardObject



76
77
78
# File 'lib/redis/cluster/transaction_adapter.rb', line 76

def discard
  # no need to do anything
end

#execObject



72
73
74
# File 'lib/redis/cluster/transaction_adapter.rb', line 72

def exec
  # no need to do anything
end

#lock_released?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/redis/cluster/transaction_adapter.rb', line 59

def lock_released?
  @lock_released
end

#multi {|transaction| ... } ⇒ Object

Yields:

  • (transaction)


63
64
65
66
67
68
69
70
# File 'lib/redis/cluster/transaction_adapter.rb', line 63

def multi
  @lock_released = true
  transaction = Redis::Cluster::TransactionAdapter::Internal.new(
    @client, @router, @command_builder, node: @node, slot: @slot, asking: @asking
  )
  yield transaction
  transaction.execute
end

#unwatchObject



84
85
86
87
# File 'lib/redis/cluster/transaction_adapter.rb', line 84

def unwatch
  @lock_released = true
  @node.call('UNWATCH')
end

#watch(*_) ⇒ Object



80
81
82
# File 'lib/redis/cluster/transaction_adapter.rb', line 80

def watch(*_)
  raise(Redis::Cluster::TransactionConsistencyError, "Can't nest watch command if you use the cluster client")
end