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
Constructor Details
#initialize(router) ⇒ OptimisticLocking
Returns a new instance of OptimisticLocking.
9 10 11 |
# File 'lib/redis_client/cluster/optimistic_locking.rb', line 9 def initialize(router) @router = router end |
Instance Method Details
#watch(keys) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/redis_client/cluster/optimistic_locking.rb', line 13 def watch(keys) slot = find_slot(keys) raise ::RedisClient::Cluster::Transaction::ConsistencyError, "unsafe watch: #{keys.join(' ')}" if slot.nil? node = @router.find_primary_node_by_slot(slot) @router.handle_redirection(node, retry_count: 1) do |nd| nd.with do |c| c.call('WATCH', *keys) yield(c, slot) rescue StandardError c.call('UNWATCH') raise end end end |