You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-36Lines changed: 21 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,24 +102,15 @@ Like `shutdown`, this will block until all connections are checked in and closed
102
102
103
103
## Reap
104
104
105
-
You can reap idle connections in the ConnectionPool instance to close connections that were created but have not been used for a certain amount of time. This can be useful to run periodically in a separate thread especially if keeping the connection open is resource intensive.
105
+
You can call `reap` periodically on the ConnectionPool instance to close connections that were created but have not been used for a certain amount of time. This can be useful in environments where connections are expensive.
106
106
107
-
You can specify how many seconds the connections have to be idle for them to be reaped.
108
-
Defaults to 60 seconds.
107
+
You can specify how many seconds the connections have to be idle for them to be reaped, defaulting to 60 seconds.
109
108
110
109
```ruby
111
110
cp =ConnectionPool.new { Redis.new }
112
-
cp.reap(idle_seconds:300) { |conn| conn.close } # Reaps connections that have been idle for 300 seconds (5 minutes).
113
-
```
114
-
115
-
### Reaper Thread
116
-
117
-
You can start your own reaper thread to reap idle connections in the ConnectionPool instance on a regular interval.
118
111
119
-
```ruby
120
-
cp =ConnectionPool.new { Redis.new }
121
-
122
-
# Start a reaper thread to reap connections that have been idle for 300 seconds (5 minutes).
112
+
# Start a reaper thread to reap connections that have been
113
+
# idle more than 300 seconds (5 minutes)
123
114
Thread.newdo
124
115
loopdo
125
116
cp.reap(idle_seconds:300) { |conn| conn.close }
@@ -139,14 +130,14 @@ It can only be done inside the block passed to `with` or `with_timeout`.
139
130
Takes an optional block that will be executed with the connection.
140
131
141
132
```ruby
142
-
pool.with do |conn|
143
-
begin
144
-
conn.execute("SELECT 1")
145
-
rescueSomeConnectionError
146
-
pool.discard_current_connection # remove the connection from the pool
147
-
raise
148
-
end
149
-
end
133
+
pool.with do |conn|
134
+
begin
135
+
conn.execute("SELECT 1")
136
+
rescueSomeConnectionError
137
+
pool.discard_current_connection # remove the connection from the pool
138
+
raise
139
+
end
140
+
end
150
141
```
151
142
152
143
## Current State
@@ -168,12 +159,11 @@ end
168
159
cp.idle # => 1
169
160
```
170
161
171
-
Upgrading from ConnectionPool 2
172
-
---------------------------------
162
+
## Upgrading from ConnectionPool 2
173
163
174
-
* Support for Rubies <3.2 has been removed.
164
+
* Support for Ruby <3.2 has been removed.
175
165
* ConnectionPool's APIs now consistently use keyword arguments everywhere.
176
-
Any positional arguments must be converted to keywords:
166
+
Positional arguments must be converted to keywords:
0 commit comments