-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,90 @@ | ||
package redis | ||
|
||
import "time" | ||
import ( | ||
"crypto/tls" | ||
"net" | ||
"time" | ||
|
||
// Config Redis Configuration | ||
"github.com/go-redis/redis" | ||
) | ||
|
||
// Config Redis parameter options | ||
type Config struct { | ||
// The network type, either tcp or unix. | ||
// Default is tcp. | ||
Network string | ||
// host:port address. | ||
Addr string | ||
|
||
// An optional password. Must match the password specified in the | ||
// Dialer creates new network connection and has priority over | ||
// Network and Addr options. | ||
Dialer func() (net.Conn, error) | ||
|
||
// Optional password. Must match the password specified in the | ||
// requirepass server configuration option. | ||
Password string | ||
// A database to be selected after connecting to server. | ||
// Database to be selected after connecting to the server. | ||
DB int | ||
|
||
// The maximum number of retries before giving up. | ||
// Maximum number of retries before giving up. | ||
// Default is to not retry failed commands. | ||
MaxRetries int | ||
// Minimum backoff between each retry. | ||
// Default is 8 milliseconds; -1 disables backoff. | ||
MinRetryBackoff time.Duration | ||
// Maximum backoff between each retry. | ||
// Default is 512 milliseconds; -1 disables backoff. | ||
MaxRetryBackoff time.Duration | ||
|
||
// Sets the deadline for establishing new connections. If reached, | ||
// dial will fail with a timeout. | ||
// Dial timeout for establishing new connections. | ||
// Default is 5 seconds. | ||
DialTimeout time.Duration | ||
// Sets the deadline for socket reads. If reached, commands will | ||
// fail with a timeout instead of blocking. | ||
// Timeout for socket reads. If reached, commands will fail | ||
// with a timeout instead of blocking. | ||
// Default is 3 seconds. | ||
ReadTimeout time.Duration | ||
// Sets the deadline for socket writes. If reached, commands will | ||
// fail with a timeout instead of blocking. | ||
// Timeout for socket writes. If reached, commands will fail | ||
// with a timeout instead of blocking. | ||
// Default is ReadTimeout. | ||
WriteTimeout time.Duration | ||
|
||
// The maximum number of socket connections. | ||
// Default is 10 connections. | ||
// Maximum number of socket connections. | ||
// Default is 10 connections per every CPU as reported by runtime.NumCPU. | ||
PoolSize int | ||
// Specifies amount of time client waits for connection if all | ||
// connections are busy before returning an error. | ||
// Default is 1 second. | ||
// Amount of time client waits for connection if all connections | ||
// are busy before returning an error. | ||
// Default is ReadTimeout + 1 second. | ||
PoolTimeout time.Duration | ||
// Amount of time after which client closes idle connections. | ||
// Should be less than server's timeout. | ||
// Default is 5 minutes. | ||
IdleTimeout time.Duration | ||
// Frequency of idle checks. | ||
// Default is 1 minute. | ||
// When minus value is set, then idle check is disabled. | ||
IdleCheckFrequency time.Duration | ||
|
||
// TLS Config to use. When set TLS will be negotiated. | ||
TLSConfig *tls.Config | ||
} | ||
|
||
func (o *Config) redisOptions() *redis.Options { | ||
return &redis.Options{ | ||
Network: o.Network, | ||
Addr: o.Addr, | ||
Dialer: o.Dialer, | ||
Password: o.Password, | ||
DB: o.DB, | ||
MaxRetries: o.MaxRetries, | ||
MinRetryBackoff: o.MinRetryBackoff, | ||
MaxRetryBackoff: o.MaxRetryBackoff, | ||
DialTimeout: o.DialTimeout, | ||
ReadTimeout: o.ReadTimeout, | ||
WriteTimeout: o.WriteTimeout, | ||
PoolSize: o.PoolSize, | ||
PoolTimeout: o.PoolTimeout, | ||
IdleTimeout: o.IdleTimeout, | ||
IdleCheckFrequency: o.IdleCheckFrequency, | ||
TLSConfig: o.TLSConfig, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters