woj-server/internal/repo/redis/redis.go
Paul Pan ec660e706e feat: add logout
Co-authored-by: cxy004 <cxy004@qq.com>
Co-authored-by: wzt <w.zhongtao@qq.com>
2022-09-17 18:10:06 +08:00

40 lines
691 B
Go

package redis
import (
"context"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/go-redis/redis/v8"
"go.uber.org/zap"
)
var _ global.Repo = (*Repo)(nil)
type Repo struct {
client *redis.Client
log *zap.Logger
}
func (r *Repo) Setup(g *global.Global) {
r.log = g.Log
r.client = redis.NewClient(&redis.Options{
Addr: g.Conf.Redis.Address,
Password: g.Conf.Redis.Password,
DB: g.Conf.Redis.Db,
})
_, err := r.client.Ping(context.Background()).Result()
if err != nil {
r.log.Fatal("Redis ping failed", zap.Error(err))
return
}
}
func (r *Repo) Get() interface{} {
return r.client
}
func (r *Repo) Close() error {
return r.client.Close()
}