Skip to content

Commit 2192c2a

Browse files
committed
Merge branch 'master' of https://github.com/mperham/redis-rb into 3.3
2 parents d6f9b46 + 4099a8f commit 2192c2a

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
@@ -54,7 +54,8 @@ listening on `localhost`, port 6379. If you need to connect to a remote
5454
server or a different port, try:
5555

5656
```ruby
57-
redis = Redis.new(:host => "10.0.1.1", :port => 6380, :db => 15)
57+
redis = Redis.new(:host => "10.0.1.1", :port => 6380, :db => 15,
58+
:read_timeout => 1, :connect_timeout => 1)
5859
```
5960

6061
You can also specify connection options as a [`redis://` URL][redis-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
:write_timeout => nil,
1717
:password => nil,
@@ -43,8 +43,16 @@ def path
4343
@options[:path]
4444
end
4545

46+
def read_timeout
47+
@options[:read_timeout]
48+
end
49+
50+
def connect_timeout
51+
@options[:connect_timeout]
52+
end
53+
4654
def timeout
47-
@options[:timeout]
55+
@options[:read_timeout]
4856
end
4957

5058
def password
@@ -427,11 +435,16 @@ def _parse_options(options)
427435
options[:port] = options[:port].to_i
428436
end
429437

430-
options[:timeout] = options[:timeout].to_f
438+
if options.has_key?(:timeout)
439+
options[:read_timeout] ||= options[:timeout]
440+
options[:connect_timeout] ||= options[:timeout]
441+
end
442+
443+
options[:read_timeout] = options[:read_timeout].to_f
431444
options[:connect_timeout] = if options[:connect_timeout]
432445
options[:connect_timeout].to_f
433446
else
434-
options[:timeout]
447+
options[:read_timeout]
435448
end
436449

437450
options[:write_timeout] = options[:write_timeout] ? options[:write_timeout].to_f : options[:timeout]

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)