37 lines
767 B
Go
37 lines
767 B
Go
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
|
|
"go_dreamfactory/lego/sys/log"
|
|
)
|
|
|
|
const ( //Redis
|
|
Redis_UserCache string = "user:%s" //会话列表
|
|
)
|
|
|
|
type IUser interface {
|
|
Update(data *pb.Cache_UserData) (err error)
|
|
Get(userId string) *pb.Cache_UserData
|
|
}
|
|
|
|
func (this *Cache) Update(data *pb.Cache_UserData) (err error) {
|
|
err = db.Defsys.User_Update(data.UserData)
|
|
if err == nil {
|
|
err = this.redis.Set(fmt.Sprintf(Redis_UserCache, data.UserData.UserId), data, -1)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *Cache) Get(userId string) *pb.Cache_UserData {
|
|
var user *pb.Cache_UserData
|
|
err := this.redis.Get(fmt.Sprintf(Redis_UserCache, userId), &user)
|
|
if err != nil {
|
|
log.Errorf("get user cache err:%v", err)
|
|
return nil
|
|
}
|
|
return user
|
|
}
|