feat: first version.
This commit is contained in:
26
redis.go
Normal file
26
redis.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
|
||||
"github.com/tx7do/kratos-bootstrap/gen/api/go/conf/v1"
|
||||
)
|
||||
|
||||
// NewRedisClient 创建Redis客户端
|
||||
func NewRedisClient(conf *conf.Data) *redis.Client {
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: conf.Redis.Addr,
|
||||
Password: conf.Redis.Password,
|
||||
DB: int(conf.Redis.Db),
|
||||
DialTimeout: conf.Redis.DialTimeout.AsDuration(),
|
||||
WriteTimeout: conf.Redis.WriteTimeout.AsDuration(),
|
||||
ReadTimeout: conf.Redis.ReadTimeout.AsDuration(),
|
||||
})
|
||||
if rdb == nil {
|
||||
log.Fatalf("failed opening connection to redis")
|
||||
return nil
|
||||
}
|
||||
rdb.AddHook(redisotel.NewTracingHook())
|
||||
|
||||
return rdb
|
||||
}
|
||||
Reference in New Issue
Block a user