| Class | ConnectionPool |
| In: |
lib/connection_pool/monotonic_time.rb
lib/connection_pool/version.rb lib/connection_pool.rb |
| Parent: | Object |
Generic connection pool class for e.g. sharing a limited number of network connections among many threads. Note: Connections are lazily created.
Example usage with block (faster):
@pool = ConnectionPool.new { Redis.new }
@pool.with do |redis|
redis.lpop('my-list') if redis.llen('my-list') > 0
end
Using optional timeout override (for that single invocation)
@pool.with(timeout: 2.0) do |redis|
redis.lpop('my-list') if redis.llen('my-list') > 0
end
Example usage replacing an existing connection (slower):
$redis = ConnectionPool.wrap { Redis.new }
def do_work
$redis.lpop('my-list') if $redis.llen('my-list') > 0
end
Accepts the following options:
| GLOBAL_MONOTONIC_CLOCK | = | class_definition.new |
Clock that cannot be set and represents monotonic time since some
unspecified starting point.
@!visibility private |
|
| VERSION | = | "2.2.2" | ||
| DEFAULTS | = | {size: 5, timeout: 5} |