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

37 lines
760 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) error
FriendGetTotal(userId string) int32
}
func (this *Cache) FriendAdd(data *pb.Cache_FriendData) error {
if err := db.Defsys.FriendApply(data); err == nil {
return this.redis.ZAdd(fmt.Sprintf(Redis_FriendCache, data.UserId))
}
return nil
}
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))
}