Skip to content

Commit 18464f2

Browse files
committed
Update README on timeouts.
1 parent 65f8886 commit 18464f2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,38 @@ end
223223
See lib/redis/errors.rb for information about what exceptions are possible.
224224

225225

226+
## Timeouts
227+
228+
The client allows you to configure connect, read, and write timeouts.
229+
Passing a single `timeout` option will set all three values:
230+
231+
```ruby
232+
Redis.new(:timeout => 1)
233+
```
234+
235+
But you can use specific values for each of them:
236+
237+
```ruby
238+
Redis.new(
239+
:connect_timeout => 0.2,
240+
:read_timeout => 1.0,
241+
:write_timeout => 0.5
242+
)
243+
```
244+
245+
When using pub/sub, you can subscribe to a channel using a timeout as well:
246+
247+
```ruby
248+
redis.subscribe_with_timeout(5, "news") do |on|
249+
on.message do |channel, message|
250+
# ...
251+
end
252+
end
253+
```
254+
255+
If no message is received after 5 seconds, the client will unsubscribe.
256+
257+
226258
## Expert-Mode Options
227259

228260
- `inherit_socket: true`: disable safety check that prevents a forked child

0 commit comments

Comments
 (0)