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.
32 lines
667 B
32 lines
667 B
package dao
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/go-kratos/kratos/pkg/cache/redis"
|
|
"github.com/go-kratos/kratos/pkg/conf/paladin"
|
|
"github.com/go-kratos/kratos/pkg/log"
|
|
)
|
|
|
|
func NewRedis() (r *redis.Redis, cf func(), err error) {
|
|
var (
|
|
cfg redis.Config
|
|
ct paladin.Map
|
|
)
|
|
if err = paladin.Get("redis.toml").Unmarshal(&ct); err != nil {
|
|
return
|
|
}
|
|
if err = ct.Get("Client").UnmarshalTOML(&cfg); err != nil {
|
|
return
|
|
}
|
|
r = redis.NewRedis(&cfg)
|
|
cf = func(){r.Close()}
|
|
return
|
|
}
|
|
|
|
func (d *dao) PingRedis(ctx context.Context) (err error) {
|
|
if _, err = d.redis.Do(ctx, "SET", "ping", "pong"); err != nil {
|
|
log.Error("conn.Set(PING) error(%v)", err)
|
|
}
|
|
return
|
|
} |