You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
678 B
37 lines
678 B
package data
|
|
|
|
import (
|
|
"customer/internal/conf"
|
|
"github.com/go-redis/redis/v9"
|
|
|
|
"github.com/go-kratos/kratos/v2/log"
|
|
"github.com/google/wire"
|
|
)
|
|
|
|
// ProviderSet is data providers.
|
|
var ProviderSetData = wire.NewSet(NewData)
|
|
|
|
// Data .
|
|
type Data struct {
|
|
// TODO wrapped database client
|
|
Rdb *redis.Client
|
|
}
|
|
|
|
// NewData .
|
|
func NewData(c *conf.Data, logger log.Logger) (*Data, func(), error) {
|
|
cleanup := func() {
|
|
log.NewHelper(logger).Info("closing the data resources")
|
|
}
|
|
|
|
// init rdb
|
|
rdb := redis.NewClient(&redis.Options{
|
|
Addr: c.Redis.Addr,
|
|
Password: "", // no password set
|
|
DB: 0, // use default DB
|
|
})
|
|
|
|
return &Data{
|
|
Rdb: rdb,
|
|
}, cleanup, nil
|
|
}
|