Class: RedlockForCollection::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/redlock_for_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|@configuration| ... } ⇒ Manager

Returns a new instance of Manager.

Yields:



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

#configurationObject (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

Examples:

configure do |configuration|
    config.pool_size = 2
    config.redis_urls = ['redis://localhost:6379']
    config.retry_delay = 2
    config.retry_count = 2
end

Yields:



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

Yields:

  • (locked_objects, unlocked_objects)


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, options, @configuration.pool)

  collection.lock(&block)
end