Skip to content

Commit

Permalink
Merge pull request redis#366 from go-redis/fix/option-defaults
Browse files Browse the repository at this point in the history
Set some sane default for every day usage.
  • Loading branch information
vmihailenco authored Sep 13, 2016
2 parents f696885 + cea5c23 commit 60d35df
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ type Options struct {
DialTimeout time.Duration
// Timeout for socket reads. If reached, commands will fail
// with a timeout instead of blocking.
// Default is 3 seconds.
ReadTimeout time.Duration
// Timeout for socket writes. If reached, commands will fail
// with a timeout instead of blocking.
// Default is 3 seconds.
WriteTimeout time.Duration

// Maximum number of socket connections.
// Default is 10 connections.
PoolSize int
// Amount of time client waits for connection if all connections
// are busy before returning an error.
// Default is 1 second.
// Default is ReadTimeout + 1 second.
PoolTimeout time.Duration
// Amount of time after which client closes idle connections.
// Should be less than server's timeout.
Expand Down Expand Up @@ -72,8 +74,17 @@ func (opt *Options) init() {
if opt.DialTimeout == 0 {
opt.DialTimeout = 5 * time.Second
}
if opt.ReadTimeout == 0 {
opt.ReadTimeout = 3 * time.Second
}
if opt.WriteTimeout == 0 {
opt.WriteTimeout = opt.ReadTimeout
}
if opt.PoolTimeout == 0 {
opt.PoolTimeout = 1 * time.Second
opt.PoolTimeout = opt.ReadTimeout + time.Second
}
if opt.IdleTimeout == 0 {
opt.IdleTimeout = 5 * time.Minute
}
if opt.IdleCheckFrequency == 0 {
opt.IdleCheckFrequency = time.Minute
Expand Down

0 comments on commit 60d35df

Please sign in to comment.