Skip to content

Commit

Permalink
style: code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mutezebra committed Nov 1, 2024
1 parent f7bd1f9 commit 04213a2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/base/client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import (

"github.com/redis/go-redis/v9"

"github.com/west2-online/fzuhelper-server/pkg/logger"

"github.com/west2-online/fzuhelper-server/config"
"github.com/west2-online/fzuhelper-server/pkg/logger"
)

// NewRedisClient 传入dbName,具体参考 constants 包
Expand All @@ -34,19 +33,19 @@ func NewRedisClient(db int) (*redis.Client, error) {
return nil, errors.New("redis config is nil")
}

l := logger.GetRedisLogger()
redis.SetLogger(l)

client := redis.NewClient(&redis.Options{
Addr: config.Redis.Addr,
Password: config.Redis.Password,
DB: db,
})
client.AddHook(l)

_, err := client.Ping(context.TODO()).Result()
if err != nil {
return nil, fmt.Errorf("client.NewRedisClient: ping redis failed: %w", err)
}

l := logger.GetRedisLogger()
redis.SetLogger(l)
client.AddHook(l)
return client, nil
}

0 comments on commit 04213a2

Please sign in to comment.