36 lines
778 B
Go
36 lines
778 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_MailCache string = "mail:%s"
|
|
)
|
|
|
|
type IMail interface {
|
|
QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error)
|
|
}
|
|
|
|
// 查询玩家邮件数据
|
|
func (this *Cache) QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) {
|
|
mail = &pb.DB_UserMailData{
|
|
UserId: uId,
|
|
}
|
|
if err = this.redis.Get(fmt.Sprintf(Redis_MailCache, uId), mail); err == nil {
|
|
return
|
|
} else if err == redis.RedisNil {
|
|
if mail, err = db.Defsys.QueryUserMail(uId); err == nil {
|
|
this.redis.Set(fmt.Sprintf(Redis_MailCache, uId), mail, -1)
|
|
} else if err == mgo.MongodbNil {
|
|
err = nil
|
|
}
|
|
}
|
|
return
|
|
}
|