refactor: remove the non-used parameter

This commit is contained in:
edwin 2024-06-05 16:45:49 +08:00
parent 58f023a8ef
commit 21a757dd30
8 changed files with 22 additions and 25 deletions

View File

@ -1070,7 +1070,7 @@ func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) {
for _, node := range nodes { for _, node := range nodes {
_, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns() _, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns()
if err != nil { 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] info := cmdsInfo[name]
if info == nil { 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 return info
} }

View File

@ -23,7 +23,6 @@ func usePrecise(dur time.Duration) bool {
func formatMs(ctx context.Context, dur time.Duration) int64 { func formatMs(ctx context.Context, dur time.Duration) int64 {
if dur > 0 && dur < time.Millisecond { if dur > 0 && dur < time.Millisecond {
internal.Logger.Printf( internal.Logger.Printf(
ctx,
"specified duration is %s, but minimal supported value is %s - truncating to 1ms", "specified duration is %s, but minimal supported value is %s - truncating to 1ms",
dur, time.Millisecond, 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 { func formatSec(ctx context.Context, dur time.Duration) int64 {
if dur > 0 && dur < time.Second { if dur > 0 && dur < time.Second {
internal.Logger.Printf( internal.Logger.Printf(
ctx,
"specified duration is %s, but minimal supported value is %s - truncating to 1s", "specified duration is %s, but minimal supported value is %s - truncating to 1s",
dur, time.Second, dur, time.Second,
) )

View File

@ -87,7 +87,7 @@ func (state *clusterState) IsConsistent(ctx context.Context) bool {
func GetSlavesAddrByName(ctx context.Context, c *SentinelClient, name string) []string { func GetSlavesAddrByName(ctx context.Context, c *SentinelClient, name string) []string {
addrs, err := c.Slaves(ctx, name).Result() addrs, err := c.Slaves(ctx, name).Result()
if err != nil { if err != nil {
internal.Logger.Printf(ctx, "sentinel: Slaves name=%q failed: %s", internal.Logger.Printf("sentinel: Slaves name=%q failed: %s",
name, err) name, err)
return []string{} return []string{}
} }

View File

@ -1,21 +1,20 @@
package internal package internal
import ( import (
"context"
"fmt" "fmt"
"log" "log"
"os" "os"
) )
type Logging interface { type Logging interface {
Printf(ctx context.Context, format string, v ...interface{}) Printf(format string, v ...interface{})
} }
type logger struct { type logger struct {
log *log.Logger 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...)) _ = l.log.Output(2, fmt.Sprintf(format, v...))
} }

View File

@ -353,7 +353,7 @@ func (p *ConnPool) popIdle() (*Conn, error) {
func (p *ConnPool) Put(ctx context.Context, cn *Conn) { func (p *ConnPool) Put(ctx context.Context, cn *Conn) {
if cn.rd.Buffered() > 0 { 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{}) p.Remove(ctx, cn, BadConnError{})
return return
} }
@ -492,7 +492,7 @@ func (p *ConnPool) reaper(frequency time.Duration) {
} }
_, err := p.ReapStaleConns() _, err := p.ReapStaleConns()
if err != nil { if err != nil {
internal.Logger.Printf(context.Background(), "ReapStaleConns failed: %s", err) internal.Logger.Printf("ReapStaleConns failed: %s", err)
continue continue
} }
case <-p.closedCh: case <-p.closedCh:

View File

@ -156,7 +156,7 @@ func (c *PubSub) closeTheCn(reason error) error {
return nil return nil
} }
if !c.closed { 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) err := c.closeConn(c.cn)
c.cn = nil c.cn = nil
@ -612,11 +612,11 @@ func (c *channel) initMsgChan() {
} }
case <-timer.C: case <-timer.C:
c.logger.Printf( 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) c, c.chanSendTimeout)
} }
default: 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: case <-timer.C:
c.logger.Printf( 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) c, c.chanSendTimeout)
} }
default: default:
c.logger.Printf(ctx, "redis: unknown message type: %T", msg) c.logger.Printf("redis: unknown message type: %T", msg)
} }
} }
}() }()

View File

@ -322,7 +322,7 @@ func (c *ringShards) Heartbeat(frequency time.Duration) {
err := shard.Client.Ping(ctx).Err() err := shard.Client.Ping(ctx).Err()
isUp := err == nil || err == pool.ErrPoolTimeout isUp := err == nil || err == pool.ErrPoolTimeout
if shard.Vote(isUp) { 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 rebalance = true
} }
} }
@ -576,7 +576,7 @@ func (c *Ring) cmdInfo(ctx context.Context, name string) *CommandInfo {
} }
info := cmdsInfo[name] info := cmdsInfo[name]
if info == nil { 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 return info
} }

View File

@ -511,7 +511,7 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) {
masterAddr, err := sentinel.GetMasterAddrByName(ctx, c.opt.MasterName).Result() masterAddr, err := sentinel.GetMasterAddrByName(ctx, c.opt.MasterName).Result()
if err != nil { 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) c.opt.MasterName, err)
_ = sentinel.Close() _ = sentinel.Close()
continue continue
@ -558,7 +558,7 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, useDisconnected bool)
slaves, err := sentinel.Slaves(ctx, c.opt.MasterName).Result() slaves, err := sentinel.Slaves(ctx, c.opt.MasterName).Result()
if err != nil { 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) c.opt.MasterName, err)
_ = sentinel.Close() _ = sentinel.Close()
continue continue
@ -584,7 +584,7 @@ func (c *sentinelFailover) slaveAddrs(ctx context.Context, useDisconnected bool)
func (c *sentinelFailover) getMasterAddr(ctx context.Context, sentinel *SentinelClient) string { func (c *sentinelFailover) getMasterAddr(ctx context.Context, sentinel *SentinelClient) string {
addr, err := sentinel.GetMasterAddrByName(ctx, c.opt.MasterName).Result() addr, err := sentinel.GetMasterAddrByName(ctx, c.opt.MasterName).Result()
if err != nil { 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) c.opt.MasterName, err)
return "" return ""
} }
@ -594,7 +594,7 @@ func (c *sentinelFailover) getMasterAddr(ctx context.Context, sentinel *Sentinel
func (c *sentinelFailover) getSlaveAddrs(ctx context.Context, sentinel *SentinelClient) []string { func (c *sentinelFailover) getSlaveAddrs(ctx context.Context, sentinel *SentinelClient) []string {
addrs, err := sentinel.Slaves(ctx, c.opt.MasterName).Result() addrs, err := sentinel.Slaves(ctx, c.opt.MasterName).Result()
if err != nil { 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) c.opt.MasterName, err)
return []string{} return []string{}
} }
@ -658,7 +658,7 @@ func (c *sentinelFailover) trySwitchMaster(ctx context.Context, addr string) {
} }
c._masterAddr = addr 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) c.opt.MasterName, addr)
if c.onFailover != nil { if c.onFailover != nil {
c.onFailover(ctx, addr) c.onFailover(ctx, addr)
@ -679,7 +679,7 @@ func (c *sentinelFailover) setSentinel(ctx context.Context, sentinel *SentinelCl
func (c *sentinelFailover) discoverSentinels(ctx context.Context) { func (c *sentinelFailover) discoverSentinels(ctx context.Context) {
sentinels, err := c.sentinel.Sentinels(ctx, c.opt.MasterName).Result() sentinels, err := c.sentinel.Sentinels(ctx, c.opt.MasterName).Result()
if err != nil { 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 return
} }
for _, sentinel := range sentinels { for _, sentinel := range sentinels {
@ -697,7 +697,7 @@ func (c *sentinelFailover) discoverSentinels(ctx context.Context) {
if ip != "" && port != "" { if ip != "" && port != "" {
sentinelAddr := net.JoinHostPort(ip, port) sentinelAddr := net.JoinHostPort(ip, port)
if !contains(c.sentinelAddrs, sentinelAddr) { 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) sentinelAddr, c.opt.MasterName)
c.sentinelAddrs = append(c.sentinelAddrs, sentinelAddr) c.sentinelAddrs = append(c.sentinelAddrs, sentinelAddr)
} }
@ -717,7 +717,7 @@ func (c *sentinelFailover) listen(pubsub *PubSub) {
if msg.Channel == "+switch-master" { if msg.Channel == "+switch-master" {
parts := strings.Split(msg.Payload, " ") parts := strings.Split(msg.Payload, " ")
if parts[0] != c.opt.MasterName { 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 continue
} }
addr := net.JoinHostPort(parts[3], parts[4]) addr := net.JoinHostPort(parts[3], parts[4])