2

I am a bit new to go lang. So need some help here.

I am using the go-redis package to make connection to redis using redis sentinal. Package :

github.com/go-redis/redis/v9

Now My problem is that whenever I execute my code it do the internal logging and do some automatic printing on the ternminal. (Note I have not used any print or log statement in my code)

Below is printing automatically on terminal : "redis: 2022/11/04 09:33:07 sentinel.go:661: sentinel: new master="redis-master" addr="127.0.0.1:6379"

**I do not want this printing of go-redis internal logs to happen and neither the go-redis should make its internal logs **

Please help me how I can disable this internal logging and auto log printing of go-redis

My code:

rdb := redis.NewFailoverClient(&redis.FailoverOptions{
    MasterName:    "master",
    SentinelAddrs: []string{":26379"},
})
rdb.Ping(ctx)

err := rdb.Set(ctx, "key", "value", 0).Err()
if err != nil {
fmt.Println(err)
}

I checked on various forums and didnt got anything for this. some people said that I can use

SetLogger() func of go-redis

But I am not getting how to use it . if someone can help me with the sample code for this.

1 Answers1

0

redis.SetLogger takes internal.Logging as argument.

You can write a no-op logger struct which satisfies this interface but does nothing in the Printf method, and use that in SetLogger method

like

type NOOPLogger struct{}

func (NOOPLogger) Printf(ctx context.Context, format string, v ...interface{}) {
    // Do nothing here
}

// Then wherever redis client is started/ connected
redis.SetLogger(NOOPLogger{})