Skip to content

Commit f0d6dd2

Browse files
committed
docs
1 parent 84a66b9 commit f0d6dd2

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

Changes.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
------
55

66
- **BREAKING CHANGES** `ConnectionPool` and `ConnectionPool::TimedStack` now
7-
use keyword arguments rather than positional arguments everywhere.
8-
See README for upgrade notes.
7+
use keyword arguments rather than positional arguments everywhere. Expected impact is minimal as most people use the `with` API, which is unchanged.
8+
```ruby
9+
pool = ConnectionPool.new(size: 5, timeout: 5)
10+
pool.checkout(1) # 2.x
11+
pool.reap(30) # 2.x
12+
pool.checkout(timeout: 1) # 3.x
13+
pool.reap(idle_seconds: 30) # 3.x
14+
```
915
- Dropped support for Ruby <3.2.0
1016

1117
2.5.5

README.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ connection pool and a raw client.
3838
$redis.then { |r| r.set 'foo' 'bar' }
3939
```
4040

41-
Optionally, you can specify a timeout override using the with-block semantics:
41+
Optionally, you can specify a timeout override:
4242

4343
``` ruby
4444
$memcached.with(timeout: 2.0) do |conn|
4545
conn.get('some-count')
4646
end
4747
```
4848

49-
This will only modify the resource-get timeout for this particular
50-
invocation.
49+
This will only modify the timeout for this particular invocation.
5150
This is useful if you want to fail-fast on certain non-critical
5251
sections when a resource is not available, or conversely if you are comfortable blocking longer on a particular resource.
5352

@@ -71,7 +70,7 @@ $redis.with do |conn|
7170
end
7271
```
7372

74-
Once you've ported your entire system to use `with`, you can simply remove `Wrapper` and use the simpler and faster `ConnectionPool`.
73+
Once you've ported your entire system to use `with`, you can remove `::Wrapper` and use `ConnectionPool` directly.
7574

7675

7776
## Shutdown
@@ -89,16 +88,17 @@ Shutting down a connection pool will block until all connections are checked in
8988

9089
## Reload
9190

92-
You can reload a ConnectionPool instance in the case it is desired to close all connections to the pool and, unlike `shutdown`, afterwards recreate connections so the pool may continue to be used.
93-
Reloading may be useful after forking the process.
91+
You can reload a ConnectionPool instance if it is necessary to close all existing connections and continue to use the pool.
92+
ConnectionPool will automatically reload if the process is forked.
93+
Use `auto_reload_after_fork: false` if you don't want this behavior.
9494

9595
```ruby
96-
cp = ConnectionPool.new { Redis.new }
97-
cp.reload { |conn| conn.quit }
96+
cp = ConnectionPool.new(auto_reload_after_fork: false) { Redis.new }
97+
cp.reload { |conn| conn.quit } # reload manually
9898
cp.with { |conn| conn.get('some-count') }
9999
```
100100

101-
Like `shutdown`, this will block until all connections are checked in and closed.
101+
Like `shutdown`, `reload` will block until all connections are checked in and closed.
102102

103103
## Reap
104104

@@ -113,28 +113,24 @@ cp = ConnectionPool.new { Redis.new }
113113
# idle more than 300 seconds (5 minutes)
114114
Thread.new do
115115
loop do
116-
cp.reap(idle_seconds: 300) { |conn| conn.close }
117-
sleep 300
116+
cp.reap(idle_seconds: 300, &:close)
117+
sleep 30
118118
end
119119
end
120120
```
121121

122122
## Discarding Connections
123123

124-
You can discard connections in the ConnectionPool instance to remove connections that are broken and can't be restarted.
125-
126-
NOTE: the connection is not closed. It will just be removed from the pool so it won't be selected again.
127-
128-
It can only be done inside the block passed to `with` or `with_timeout`.
129-
124+
You can discard connections in the ConnectionPool instance to remove connections that are broken and can't be repaired.
125+
It can only be done inside the block passed to `with`.
130126
Takes an optional block that will be executed with the connection.
131127

132128
```ruby
133129
pool.with do |conn|
134130
begin
135131
conn.execute("SELECT 1")
136132
rescue SomeConnectionError
137-
pool.discard_current_connection # remove the connection from the pool
133+
pool.discard_current_connection(&:close) # remove the connection from the pool
138134
raise
139135
end
140136
end

0 commit comments

Comments
 (0)