Source File
universal.go
Belonging Package
github.com/go-redis/redis/v8
package redis
import (
)
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
OnConnect func(ctx context.Context, cn *Conn) error
Username string
Password string
SentinelPassword string
MaxRetries int
MinRetryBackoff time.Duration
MaxRetryBackoff time.Duration
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
PoolSize int
MinIdleConns int
MaxConnAge time.Duration
PoolTimeout time.Duration
IdleTimeout time.Duration
IdleCheckFrequency time.Duration
TLSConfig *tls.Config
func ( *UniversalOptions) () *ClusterOptions {
if len(.Addrs) == 0 {
.Addrs = []string{"127.0.0.1:6379"}
}
return &ClusterOptions{
Addrs: .Addrs,
Dialer: .Dialer,
OnConnect: .OnConnect,
Username: .Username,
Password: .Password,
MaxRedirects: .MaxRedirects,
ReadOnly: .ReadOnly,
RouteByLatency: .RouteByLatency,
RouteRandomly: .RouteRandomly,
MaxRetries: .MaxRetries,
MinRetryBackoff: .MinRetryBackoff,
MaxRetryBackoff: .MaxRetryBackoff,
DialTimeout: .DialTimeout,
ReadTimeout: .ReadTimeout,
WriteTimeout: .WriteTimeout,
PoolSize: .PoolSize,
MinIdleConns: .MinIdleConns,
MaxConnAge: .MaxConnAge,
PoolTimeout: .PoolTimeout,
IdleTimeout: .IdleTimeout,
IdleCheckFrequency: .IdleCheckFrequency,
TLSConfig: .TLSConfig,
}
}
func ( *UniversalOptions) () *FailoverOptions {
if len(.Addrs) == 0 {
.Addrs = []string{"127.0.0.1:26379"}
}
return &FailoverOptions{
SentinelAddrs: .Addrs,
MasterName: .MasterName,
Dialer: .Dialer,
OnConnect: .OnConnect,
DB: .DB,
Username: .Username,
Password: .Password,
SentinelPassword: .SentinelPassword,
MaxRetries: .MaxRetries,
MinRetryBackoff: .MinRetryBackoff,
MaxRetryBackoff: .MaxRetryBackoff,
DialTimeout: .DialTimeout,
ReadTimeout: .ReadTimeout,
WriteTimeout: .WriteTimeout,
PoolSize: .PoolSize,
MinIdleConns: .MinIdleConns,
MaxConnAge: .MaxConnAge,
PoolTimeout: .PoolTimeout,
IdleTimeout: .IdleTimeout,
IdleCheckFrequency: .IdleCheckFrequency,
TLSConfig: .TLSConfig,
}
}
func ( *UniversalOptions) () *Options {
:= "127.0.0.1:6379"
if len(.Addrs) > 0 {
= .Addrs[0]
}
return &Options{
Addr: ,
Dialer: .Dialer,
OnConnect: .OnConnect,
DB: .DB,
Username: .Username,
Password: .Password,
MaxRetries: .MaxRetries,
MinRetryBackoff: .MinRetryBackoff,
MaxRetryBackoff: .MaxRetryBackoff,
DialTimeout: .DialTimeout,
ReadTimeout: .ReadTimeout,
WriteTimeout: .WriteTimeout,
PoolSize: .PoolSize,
MinIdleConns: .MinIdleConns,
MaxConnAge: .MaxConnAge,
PoolTimeout: .PoolTimeout,
IdleTimeout: .IdleTimeout,
IdleCheckFrequency: .IdleCheckFrequency,
TLSConfig: .TLSConfig,
}
}
type UniversalClient interface {
Cmdable
Context() context.Context
AddHook(Hook)
Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error
Do(ctx context.Context, args ...interface{}) *Cmd
Process(ctx context.Context, cmd Cmder) error
Subscribe(ctx context.Context, channels ...string) *PubSub
PSubscribe(ctx context.Context, channels ...string) *PubSub
Close() error
}
var (
_ UniversalClient = (*Client)(nil)
_ UniversalClient = (*ClusterClient)(nil)
_ UniversalClient = (*Ring)(nil)
)
func ( *UniversalOptions) UniversalClient {
if .MasterName != "" {
return NewFailoverClient(.Failover())
} else if len(.Addrs) > 1 {
return NewClusterClient(.Cluster())
}
return NewClient(.Simple())
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |