Class: RedisClient::Cluster::OptimisticLocking
- Inherits:
-
Object
- Object
- RedisClient::Cluster::OptimisticLocking
- Defined in:
- lib/redis_client/cluster/optimistic_locking.rb
Instance Method Summary collapse
-
#initialize(router) ⇒ OptimisticLocking
constructor
A new instance of OptimisticLocking.
-
#watch(keys) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(router) ⇒ OptimisticLocking
Returns a new instance of OptimisticLocking.
9 10 11 12 |
# File 'lib/redis_client/cluster/optimistic_locking.rb', line 9 def initialize(router) @router = router @asking = false end |
Instance Method Details
#watch(keys) ⇒ Object
rubocop:disable Metrics/AbcSize
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/redis_client/cluster/optimistic_locking.rb', line 14 def watch(keys) # rubocop:disable Metrics/AbcSize slot = find_slot(keys) raise ::RedisClient::Cluster::Transaction::ConsistencyError, "unsafe watch: #{keys.join(' ')}" if slot.nil? handle_redirection(slot, retry_count: 1) do |nd| nd.with do |c| c.ensure_connected_cluster_scoped(retryable: false) do c.call('asking') if @asking c.call('watch', *keys) begin yield(c, slot, @asking) rescue ::RedisClient::ConnectionError # No need to unwatch on a connection error. raise rescue StandardError c.call('unwatch') raise end rescue ::RedisClient::CommandError => e @router.renew_cluster_state if e..start_with?('CLUSTERDOWN') raise end rescue ::RedisClient::ConnectionError @router.renew_cluster_state raise end end end |