Exemplo n.º 1
0
func RedisAddFriend(uid, fid uint64, typ int) error {
	userKey := ""
	if err := RedisDeleteFriend(uid, fid, typ); err != nil {
		return errors.As(err, uid, fid, typ)
	}

	if typ == 1 {
		userKey = fmt.Sprintf("%s%d", SET_WHITELIST, uid)
	} else {
		userKey = fmt.Sprintf("%s%d", SET_BLACKLIST, uid)
		// 加入黑名单 删除白名单
		if err := RedisDeleteFriend(uid, fid, 1); err != nil {
			return errors.As(err, uid, fid, typ)
		}
	}

	val := fmt.Sprintf("%d", fid)
	redis.RedisSAdd(userKey, val)

	// 双向好友
	if typ == 1 {
		key_2 := fmt.Sprintf("%s%d", SET_WHITELIST, fid)
		uid_2 := fmt.Sprintf("%d", uid)
		redis.RedisSAdd(key_2, uid_2)
	}

	return nil
}
Exemplo n.º 2
0
func RedisAddTeamMember(tid, uid uint64) error {
	count := RedisTeamMemberCount(tid)
	if int(count) >= MAX_MEMBER_NUM_TEAM {
		return errors.New("team member too many")
	}
	userKey := fmt.Sprintf("%s%d", SET_TEAM_MEMBER, tid)
	val := fmt.Sprintf("%d", uid)

	redis.RedisSAdd(userKey, val)

	//member version
	val = fmt.Sprintf("%d", time.Now().Unix())
	userKey = fmt.Sprintf("%s%d", KEY_TEAM_MEMBER_VER, tid)
	redis.RedisSet(userKey, val)

	userKey = fmt.Sprintf("%s%d", SET_USERS_TEAM, uid)
	val = fmt.Sprintf("%d", tid)
	redis.RedisSAdd(userKey, val)

	return nil
}
Exemplo n.º 3
0
func RedisCreateTeam(team *TeamInfo) error {
	b, err := json.Marshal(*team)
	if err != nil {
		return errors.As(err, *team)
	}

	userKey := fmt.Sprintf("%s%d", KEY_TEAM_INFO, team.TeamId)
	redis.RedisSet(userKey, string(b))

	userKey = fmt.Sprintf("%s%d", SET_USERS_TEAM, team.Uid)
	val := fmt.Sprintf("%d", team.TeamId)

	redis.RedisSAdd(userKey, val)

	//info version
	val = fmt.Sprintf("%d", time.Now().Unix())
	userKey = fmt.Sprintf("%s%d", KEY_TEAM_INFO_VER, team.TeamId)
	redis.RedisSet(userKey, val)

	return nil
}