A cloud-native Go microservices framework with cli tool for productivity.
29.34k
stars
3.96k
forks
source link
The go-zero/core/stores/redis component cannot use hooks. If hooks are used, a null pointer error will occur. #4416
Closed
fishJack01 closed 1 month ago
// 初始化redis func NewRedis(c config.Config) map[string]redis.Redis { connMap := make(map[string]redis.Redis) for _, n := range c.DB.Mysql.DataBase { rdb := redis.MustNewRedis( c.DB.Redis, redis.WithHook(&cache.SiteCodeHook{SiteCode: n}), redis.WithHook(&cache.TracingHook{ Tracer: otel.Tracer(fmt.Sprintf("redis-tracer")), })) if ok := rdb.Ping(); !ok { panic(fmt.Sprintf("redis connect err;~~~~连接信息:host=%s,port=%s", c.DB.Redis.Host, c.DB.Redis.Pass)) } connMap[n] = rdb } return connMap }
error:panic: runtime error: invalid memory address or nil pointer dereference
If you delete the hook, you can use it. If you add the hook, you will get a null pointer error.