1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Rework Options initialisation.

This commit is contained in:
Vladimir Mihailenco
2016-06-05 11:10:30 +00:00
parent 08d3790ec5
commit 079b7ce393
5 changed files with 34 additions and 51 deletions

View File

@ -41,10 +41,7 @@ type ClusterClient struct {
// NewClusterClient returns a Redis Cluster client as described in
// http://redis.io/topics/cluster-spec.
func NewClusterClient(opt *ClusterOptions) *ClusterClient {
if opt.RouteByLatency {
opt.ReadOnly = true
}
opt.init()
client := &ClusterClient{
opt: opt,
nodes: make(map[string]*clusterNode),
@ -246,7 +243,7 @@ func (c *ClusterClient) Process(cmd Cmder) {
var ask bool
slot, node := c.cmdSlotAndNode(cmd)
for attempt := 0; attempt <= c.opt.getMaxRedirects(); attempt++ {
for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
if attempt > 0 {
cmd.reset()
}
@ -419,7 +416,7 @@ func (c *ClusterClient) pipelineExec(cmds []Cmder) error {
cmdsMap[node] = append(cmdsMap[node], cmd)
}
for attempt := 0; attempt <= c.opt.getMaxRedirects(); attempt++ {
for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
failedCmds := make(map[*clusterNode][]Cmder)
for node, cmds := range cmdsMap {
@ -516,14 +513,16 @@ type ClusterOptions struct {
IdleCheckFrequency time.Duration
}
func (opt *ClusterOptions) getMaxRedirects() int {
func (opt *ClusterOptions) init() {
if opt.MaxRedirects == -1 {
return 0
opt.MaxRedirects = 0
} else if opt.MaxRedirects == 0 {
opt.MaxRedirects = 16
}
if opt.MaxRedirects == 0 {
return 16
if opt.RouteByLatency {
opt.ReadOnly = true
}
return opt.MaxRedirects
}
func (opt *ClusterOptions) clientOptions() *Options {