mirror of
https://github.com/mperham/connection_pool
synced 2023-03-27 23:22:21 -04:00
additional test and doc update
This commit is contained in:
parent
99c2f0ff04
commit
26c1b1f957
2 changed files with 21 additions and 2 deletions
13
README.md
13
README.md
|
@ -42,6 +42,19 @@ If all the objects in the connection pool are in use, `with` will block
|
|||
until one becomes available. If no object is available within `:timeout` seconds,
|
||||
`with` will raise a `Timeout::Error`.
|
||||
|
||||
Optionally, you can specify a timeout override using the with-block semantics:
|
||||
|
||||
``` ruby
|
||||
@memcached.with(:timeout => 2.0) do |dalli|
|
||||
dalli.get('some-count')
|
||||
end
|
||||
```
|
||||
|
||||
This will only modify the resource-get timeout for this particular invocation. This
|
||||
is useful if you want to fail-fast on certain non critical sections when a resource
|
||||
is not available, or conversely if you are comfortable blocking longer on a particular
|
||||
resource. This is not implemented in the below `ConnectionPool::Wrapper` class.
|
||||
|
||||
You can use `ConnectionPool::Wrapper` to wrap a single global connection, making
|
||||
it easier to port your connection code over time:
|
||||
|
||||
|
|
|
@ -12,6 +12,12 @@ require 'connection_pool/timed_stack'
|
|||
# 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 }
|
||||
|
@ -43,7 +49,7 @@ class ConnectionPool
|
|||
@key = :"current-#{@available.object_id}"
|
||||
end
|
||||
|
||||
def with options = {}
|
||||
def with(options = {})
|
||||
conn = checkout(options)
|
||||
begin
|
||||
yield conn
|
||||
|
@ -52,7 +58,7 @@ class ConnectionPool
|
|||
end
|
||||
end
|
||||
|
||||
def checkout options = {}
|
||||
def checkout(options = {})
|
||||
stack = ::Thread.current[@key] ||= []
|
||||
|
||||
if stack.empty?
|
||||
|
|
Loading…
Reference in a new issue