44 lines
976 B
Go
44 lines
976 B
Go
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
|
|
"github.com/liwei1dao/lego/sys/mgo"
|
|
"github.com/liwei1dao/lego/sys/redis"
|
|
)
|
|
|
|
const ( //Redis
|
|
Redis_PackCache string = "pack:%s"
|
|
)
|
|
|
|
const ()
|
|
|
|
type IPack interface {
|
|
QueryUserPack(uId string) (pack *pb.DB_UserPackData, err error)
|
|
}
|
|
|
|
///查询用户背包数据
|
|
func (this *Cache) QueryUserPack(uId string) (pack *pb.DB_UserPackData, err error) {
|
|
pack = &pb.DB_UserPackData{
|
|
UserId: uId,
|
|
}
|
|
if err = this.redis.Get(fmt.Sprintf(Redis_PackCache, uId), pack); err == nil {
|
|
return
|
|
} else if err == redis.RedisNil {
|
|
if pack, err = db.Defsys.QueryUserPack(uId); err == nil {
|
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, -1)
|
|
} else if err == mgo.MongodbNil {
|
|
err = nil
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
///查询用户背包数据
|
|
func (this *Cache) UpdateUserPack(pack *pb.DB_UserPackData) (err error) {
|
|
err = this.redis.Set(fmt.Sprintf(Redis_PackCache, pack.UserId), pack, -1)
|
|
return
|
|
}
|