From 21a757dd308d520382b2b51cefdfcec99ec0e085 Mon Sep 17 00:00:00 2001 From: edwin Date: Wed, 5 Jun 2024 16:45:49 +0800 Subject: [PATCH] refactor: remove the non-used parameter --- cluster.go | 4 ++-- commands.go | 2 -- export_test.go | 2 +- internal/log.go | 5 ++--- internal/pool/pool.go | 4 ++-- pubsub.go | 10 +++++----- ring.go | 4 ++-- sentinel.go | 16 ++++++++-------- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/cluster.go b/cluster.go index a54f2f37..13b2469a 100644 --- a/cluster.go +++ b/cluster.go @@ -1070,7 +1070,7 @@ func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) { for _, node := range nodes { _, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns() if err != nil { - internal.Logger.Printf(c.Context(), "ReapStaleConns failed: %s", err) + internal.Logger.Printf("ReapStaleConns failed: %s", err) } } } @@ -1622,7 +1622,7 @@ func (c *ClusterClient) cmdInfo(name string) *CommandInfo { info := cmdsInfo[name] if info == nil { - internal.Logger.Printf(c.Context(), "info for cmd=%s not found", name) + internal.Logger.Printf("info for cmd=%s not found", name) } return info } diff --git a/commands.go b/commands.go index 0ee53b33..d1f801ed 100644 --- a/commands.go +++ b/commands.go @@ -23,7 +23,6 @@ func usePrecise(dur time.Duration) bool { func formatMs(ctx context.Context, dur time.Duration) int64 { if dur > 0 && dur < time.Millisecond { internal.Logger.Printf( - ctx, "specified duration is %s, but minimal supported value is %s - truncating to 1ms", dur, time.Millisecond, ) @@ -35,7 +34,6 @@ func formatMs(ctx context.Context, dur time.Duration) int64 { func formatSec(ctx context.Context, dur time.Duration) int64 { if dur > 0 && dur < time.Second { internal.Logger.Printf( - ctx, "specified duration is %s, but minimal supported value is %s - truncating to 1s", dur, time.Second, ) diff --git a/export_test.go b/export_test.go index 49c4b94c..b367b1b3 100644 --- a/export_test.go +++ b/export_test.go @@ -87,7 +87,7 @@ func (state *clusterState) IsConsistent(ctx context.Context) bool { func GetSlavesAddrByName(ctx context.Context, c *SentinelClient, name string) []string { addrs, err := c.Slaves(ctx, name).Result() if err != nil { - internal.Logger.Printf(ctx, "sentinel: Slaves name=%q failed: %s", + internal.Logger.Printf("sentinel: Slaves name=%q failed: %s", name, err) return []string{} } diff --git a/internal/log.go b/internal/log.go index c8b9213d..395c32cb 100644 --- a/internal/log.go +++ b/internal/log.go @@ -1,21 +1,20 @@ package internal import ( - "context" "fmt" "log" "os" ) type Logging interface { - Printf(ctx context.Context, format string, v ...interface{}) + Printf(format string, v ...interface{}) } type logger struct { log *log.Logger } -func (l *logger) Printf(ctx context.Context, format string, v ...interface{}) { +func (l *logger) Printf(format string, v ...interface{}) { _ = l.log.Output(2, fmt.Sprintf(format, v...)) } diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 3a6ecb27..40f41cfd 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -353,7 +353,7 @@ func (p *ConnPool) popIdle() (*Conn, error) { func (p *ConnPool) Put(ctx context.Context, cn *Conn) { if cn.rd.Buffered() > 0 { - internal.Logger.Printf(ctx, "Conn has unread data") + internal.Logger.Printf("Conn has unread data") p.Remove(ctx, cn, BadConnError{}) return } @@ -492,7 +492,7 @@ func (p *ConnPool) reaper(frequency time.Duration) { } _, err := p.ReapStaleConns() if err != nil { - internal.Logger.Printf(context.Background(), "ReapStaleConns failed: %s", err) + internal.Logger.Printf("ReapStaleConns failed: %s", err) continue } case <-p.closedCh: diff --git a/pubsub.go b/pubsub.go index b43ed524..7cf8eff4 100644 --- a/pubsub.go +++ b/pubsub.go @@ -156,7 +156,7 @@ func (c *PubSub) closeTheCn(reason error) error { return nil } if !c.closed { - internal.Logger.Printf(c.getContext(), "redis: discarding bad PubSub connection: %s", reason) + internal.Logger.Printf("redis: discarding bad PubSub connection: %s", reason) } err := c.closeConn(c.cn) c.cn = nil @@ -612,11 +612,11 @@ func (c *channel) initMsgChan() { } case <-timer.C: c.logger.Printf( - ctx, "redis: %+v channel is full for %s (message is dropped)", + "redis: %+v channel is full for %s (message is dropped)", c, c.chanSendTimeout) } default: - c.logger.Printf(ctx, "redis: unknown message type: %T", msg) + c.logger.Printf("redis: unknown message type: %T", msg) } } }() @@ -666,11 +666,11 @@ func (c *channel) initAllChan() { } case <-timer.C: c.logger.Printf( - ctx, "redis: %+v channel is full for %s (message is dropped)", + "redis: %+v channel is full for %s (message is dropped)", c, c.chanSendTimeout) } default: - c.logger.Printf(ctx, "redis: unknown message type: %T", msg) + c.logger.Printf("redis: unknown message type: %T", msg) } } }() diff --git a/ring.go b/ring.go index 4df00fc8..7085f925 100644 --- a/ring.go +++ b/ring.go @@ -322,7 +322,7 @@ func (c *ringShards) Heartbeat(frequency time.Duration) { err := shard.Client.Ping(ctx).Err() isUp := err == nil || err == pool.ErrPoolTimeout if shard.Vote(isUp) { - internal.Logger.Printf(context.Background(), "ring shard state changed: %s", shard) + internal.Logger.Printf("ring shard state changed: %s", shard) rebalance = true } } @@ -576,7 +576,7 @@ func (c *Ring) cmdInfo(ctx context.Context, name string) *CommandInfo { } info := cmdsInfo[name] if info == nil { - internal.Logger.Printf(ctx, "info for cmd=%s not found", name) + internal.Logger.Printf("info for cmd=%s not found", name) } return info } diff --git a/sentinel.go b/sentinel.go index ec6221dc..e396b8fd 100644 --- a/sentinel.go +++ b/sentinel.go @@ -511,7 +511,7 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) { masterAddr, err := sentinel.GetMasterAddrByName(ctx, c.opt.MasterName).Result() if err != nil { - internal.Logger.Printf(ctx, "sentinel: GetMasterAddrByName master=%q failed: %s", + internal.Logger.Printf("sentinel: GetMasterAddrByName master=%q failed: %s", c.opt.MasterName, err) _ = sentinel.Close() continue @@ -558,7 +558,7 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, useDisconnected bool) slaves, err := sentinel.Slaves(ctx, c.opt.MasterName).Result() if err != nil { - internal.Logger.Printf(ctx, "sentinel: Slaves master=%q failed: %s", + internal.Logger.Printf("sentinel: Slaves master=%q failed: %s", c.opt.MasterName, err) _ = sentinel.Close() continue @@ -584,7 +584,7 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, useDisconnected bool) func (c *sentinelFailover) getMasterAddr(ctx context.Context, sentinel *SentinelClient) string { addr, err := sentinel.GetMasterAddrByName(ctx, c.opt.MasterName).Result() if err != nil { - internal.Logger.Printf(ctx, "sentinel: GetMasterAddrByName name=%q failed: %s", + internal.Logger.Printf("sentinel: GetMasterAddrByName name=%q failed: %s", c.opt.MasterName, err) return "" } @@ -594,7 +594,7 @@ func (c *sentinelFailover) getMasterAddr(ctx context.Context, sentinel *Sentinel func (c *sentinelFailover) getSlaveAddrs(ctx context.Context, sentinel *SentinelClient) []string { addrs, err := sentinel.Slaves(ctx, c.opt.MasterName).Result() if err != nil { - internal.Logger.Printf(ctx, "sentinel: Slaves name=%q failed: %s", + internal.Logger.Printf("sentinel: Slaves name=%q failed: %s", c.opt.MasterName, err) return []string{} } @@ -658,7 +658,7 @@ func (c *sentinelFailover) trySwitchMaster(ctx context.Context, addr string) { } c._masterAddr = addr - internal.Logger.Printf(ctx, "sentinel: new master=%q addr=%q", + internal.Logger.Printf("sentinel: new master=%q addr=%q", c.opt.MasterName, addr) if c.onFailover != nil { c.onFailover(ctx, addr) @@ -679,7 +679,7 @@ func (c *sentinelFailover) setSentinel(ctx context.Context, sentinel *SentinelCl func (c *sentinelFailover) discoverSentinels(ctx context.Context) { sentinels, err := c.sentinel.Sentinels(ctx, c.opt.MasterName).Result() if err != nil { - internal.Logger.Printf(ctx, "sentinel: Sentinels master=%q failed: %s", c.opt.MasterName, err) + internal.Logger.Printf("sentinel: Sentinels master=%q failed: %s", c.opt.MasterName, err) return } for _, sentinel := range sentinels { @@ -697,7 +697,7 @@ func (c *sentinelFailover) discoverSentinels(ctx context.Context) { if ip != "" && port != "" { sentinelAddr := net.JoinHostPort(ip, port) if !contains(c.sentinelAddrs, sentinelAddr) { - internal.Logger.Printf(ctx, "sentinel: discovered new sentinel=%q for master=%q", + internal.Logger.Printf("sentinel: discovered new sentinel=%q for master=%q", sentinelAddr, c.opt.MasterName) c.sentinelAddrs = append(c.sentinelAddrs, sentinelAddr) } @@ -717,7 +717,7 @@ func (c *sentinelFailover) listen(pubsub *PubSub) { if msg.Channel == "+switch-master" { parts := strings.Split(msg.Payload, " ") if parts[0] != c.opt.MasterName { - internal.Logger.Printf(pubsub.getContext(), "sentinel: ignore addr for master=%q", parts[0]) + internal.Logger.Printf("sentinel: ignore addr for master=%q", parts[0]) continue } addr := net.JoinHostPort(parts[3], parts[4])