go_dreamfactory/sys/cache/friend.go
2022-06-08 18:00:58 +08:00

37 lines
774 B
Go

package cache
import (
"fmt"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
)
const ( //Redis
Redis_FriendCache string = "friend:%s"
)
func getRdsUserKey(userId string) string {
return fmt.Sprintf(Redis_UserCache, userId)
}
type IFriend interface {
FriendAdd(data *pb.Cache_FriendData) (err error)
FriendGetTotal(userId string) int32
}
func (this *Cache) FriendAdd(data *pb.Cache_FriendData) (err error) {
if err = db.Defsys.FriendApply(data); err == nil {
err = this.redis.Set(fmt.Sprintf(Redis_FriendCache, data.UserId), data, 0)
}
return
}
func (this *Cache) FriendGetTotal(userId string) int32 {
var friend *pb.Cache_FriendData
err := this.redis.Get(getRdsUserKey(userId), &friend)
if err != nil {
return 0
}
return int32(len(friend.FriendId))
}