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

Add ctx as first arg

This commit is contained in:
Vladimir Mihailenco
2020-03-11 16:26:42 +02:00
parent 64bb0b7f3a
commit f5593121e0
36 changed files with 3200 additions and 2970 deletions

View File

@ -1,6 +1,7 @@
package redis
import (
"context"
"fmt"
"net"
"strings"
@ -17,12 +18,12 @@ func (c *PubSub) SetNetConn(netConn net.Conn) {
c.cn = pool.NewConn(netConn)
}
func (c *ClusterClient) LoadState() (*clusterState, error) {
return c.loadState()
func (c *ClusterClient) LoadState(ctx context.Context) (*clusterState, error) {
return c.loadState(ctx)
}
func (c *ClusterClient) SlotAddrs(slot int) []string {
state, err := c.state.Get()
func (c *ClusterClient) SlotAddrs(ctx context.Context, slot int) []string {
state, err := c.state.Get(ctx)
if err != nil {
panic(err)
}
@ -34,8 +35,8 @@ func (c *ClusterClient) SlotAddrs(slot int) []string {
return addrs
}
func (c *ClusterClient) Nodes(key string) ([]*clusterNode, error) {
state, err := c.state.Reload()
func (c *ClusterClient) Nodes(ctx context.Context, key string) ([]*clusterNode, error) {
state, err := c.state.Reload(ctx)
if err != nil {
return nil, err
}
@ -48,8 +49,8 @@ func (c *ClusterClient) Nodes(key string) ([]*clusterNode, error) {
return nodes, nil
}
func (c *ClusterClient) SwapNodes(key string) error {
nodes, err := c.Nodes(key)
func (c *ClusterClient) SwapNodes(ctx context.Context, key string) error {
nodes, err := c.Nodes(ctx, key)
if err != nil {
return err
}
@ -57,12 +58,12 @@ func (c *ClusterClient) SwapNodes(key string) error {
return nil
}
func (state *clusterState) IsConsistent() bool {
func (state *clusterState) IsConsistent(ctx context.Context) bool {
if len(state.Masters) < 3 {
return false
}
for _, master := range state.Masters {
s := master.Client.Info("replication").Val()
s := master.Client.Info(ctx, "replication").Val()
if !strings.Contains(s, "role:master") {
return false
}
@ -72,7 +73,7 @@ func (state *clusterState) IsConsistent() bool {
return false
}
for _, slave := range state.Slaves {
s := slave.Client.Info("replication").Val()
s := slave.Client.Info(ctx, "replication").Val()
if !strings.Contains(s, "role:slave") {
return false
}