Class: RedlockForCollection::Manager
- Inherits:
-
Object
- Object
- RedlockForCollection::Manager
- Defined in:
- lib/redlock_for_collection.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#configure {|Configuration| ... } ⇒ Object
redlock_pool = ConnectionPool.new { Redlock::Client.new() }.
-
#initialize {|@configuration| ... } ⇒ Manager
constructor
A new instance of Manager.
-
#with_lock(objects_collection, options: {}) {|locked_objects, unlocked_objects| ... } ⇒ Object
:key_methodinvoked onobjectofobjects_collectionto generate shared key.
Constructor Details
#initialize {|@configuration| ... } ⇒ Manager
Returns a new instance of Manager.
9 10 11 12 13 |
# File 'lib/redlock_for_collection.rb', line 9 def initialize @configuration = Configuration.new yield @configuration if block_given? end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
7 8 9 |
# File 'lib/redlock_for_collection.rb', line 7 def configuration @configuration end |
Instance Method Details
#configure {|Configuration| ... } ⇒ Object
redlock_pool = ConnectionPool.new { Redlock::Client.new() }
configure do |configuration|
config.pool = redlock_pool
end
30 31 32 |
# File 'lib/redlock_for_collection.rb', line 30 def configure(&block) block.yield @configuration end |
#with_lock(objects_collection, options: {}) {|locked_objects, unlocked_objects| ... } ⇒ Object
:key_method invoked on object of objects_collection to generate shared key. :key_prefix prepended to the shared key if lock validity < :min_validity then lock is treated as expired locked_objects is successfully locked objects of collections unlocked_objects is unsuccessfully locked objects of collections for any reasons
43 44 45 46 47 |
# File 'lib/redlock_for_collection.rb', line 43 def with_lock(objects_collection, options: {}, &block) collection = Collection.new(objects_collection, , @configuration.pool) collection.lock(&block) end |