Skip to content

Commit

Permalink
Merge pull request redis#99 from go-redis/fix/release-reloading-with-…
Browse files Browse the repository at this point in the history
…delay

cluster: release reloading with delay.
  • Loading branch information
vmihailenco committed May 26, 2015
2 parents b1946ee + 40bad36 commit b70f364
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 10 additions & 6 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ func (c *ClusterClient) slotAddrs(slot int) []string {
return addrs
}

func (c *ClusterClient) slotMasterAddr(slot int) string {
addrs := c.slotAddrs(slot)
if len(addrs) > 0 {
return addrs[0]
}
return ""
}

// randomClient returns a Client for the first live node.
func (c *ClusterClient) randomClient() (client *Client, err error) {
for i := 0; i < 10; i++ {
Expand All @@ -118,11 +126,7 @@ func (c *ClusterClient) process(cmd Cmder) {

slot := hashSlot(cmd.clusterKey())

var addr string
if addrs := c.slotAddrs(slot); len(addrs) > 0 {
addr = addrs[0] // First address is master.
}

addr := c.slotMasterAddr(slot)
client, err := c.getClient(addr)
if err != nil {
cmd.setErr(err)
Expand Down Expand Up @@ -163,7 +167,7 @@ func (c *ClusterClient) process(cmd Cmder) {
var addr string
moved, ask, addr = isMovedError(err)
if moved || ask {
if moved {
if moved && c.slotMasterAddr(slot) != addr {
c.lazyReloadSlots()
}
client, err = c.getClient(addr)
Expand Down
8 changes: 1 addition & 7 deletions cluster_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ func (c *ClusterPipeline) Exec() (cmds []Cmder, retErr error) {
cmdsMap := make(map[string][]Cmder)
for _, cmd := range cmds {
slot := hashSlot(cmd.clusterKey())
addrs := c.cluster.slotAddrs(slot)

var addr string
if len(addrs) > 0 {
addr = addrs[0] // First address is master.
}

addr := c.cluster.slotMasterAddr(slot)
cmdsMap[addr] = append(cmdsMap[addr], cmd)
}

Expand Down

0 comments on commit b70f364

Please sign in to comment.