Skip to content

Commit 4099a8f

Browse files
committed
Rename timeout option to read_timeout, update README, #437
1 parent 860bcd3 commit 4099a8f

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ listening on `localhost`, port 6379. If you need to connect to a remote
4040
server or a different port, try:
4141

4242
```ruby
43-
redis = Redis.new(:host => "10.0.1.1", :port => 6380, :db => 15)
43+
redis = Redis.new(:host => "10.0.1.1", :port => 6380, :db => 15,
44+
:read_timeout => 1, :connect_timeout => 1)
4445
```
4546

4647
You can also specify connection options as an URL:

lib/redis/client.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Client
1111
:host => "127.0.0.1",
1212
:port => 6379,
1313
:path => nil,
14-
:timeout => 5.0,
14+
:read_timeout => 5.0,
1515
:connect_timeout => 5.0,
1616
:password => nil,
1717
:db => 0,
@@ -42,8 +42,16 @@ def path
4242
@options[:path]
4343
end
4444

45+
def read_timeout
46+
@options[:read_timeout]
47+
end
48+
49+
def connect_timeout
50+
@options[:connect_timeout]
51+
end
52+
4553
def timeout
46-
@options[:timeout]
54+
@options[:read_timeout]
4755
end
4856

4957
def password
@@ -422,11 +430,16 @@ def _parse_options(options)
422430
options[:port] = options[:port].to_i
423431
end
424432

425-
options[:timeout] = options[:timeout].to_f
433+
if options.has_key?(:timeout)
434+
options[:read_timeout] ||= options[:timeout]
435+
options[:connect_timeout] ||= options[:timeout]
436+
end
437+
438+
options[:read_timeout] = options[:read_timeout].to_f
426439
options[:connect_timeout] = if options[:connect_timeout]
427440
options[:connect_timeout].to_f
428441
else
429-
options[:timeout]
442+
options[:read_timeout]
430443
end
431444

432445
options[:db] = options[:db].to_i

lib/redis/connection/hiredis.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def self.connect(config)
1818
end
1919

2020
instance = new(connection)
21-
instance.timeout = config[:timeout]
21+
instance.timeout = config[:read_timeout]
2222
instance
2323
rescue Errno::ETIMEDOUT
2424
raise TimeoutError

lib/redis/connection/synchrony.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def self.connect(config)
8181
raise Errno::ECONNREFUSED if Fiber.yield == :refused
8282

8383
instance = new(conn)
84-
instance.timeout = config[:timeout]
84+
instance.timeout = config[:read_timeout]
8585
instance
8686
end
8787

0 commit comments

Comments
 (0)