Пример #1
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
}
Пример #2
0
func GetNextTeamId(uid uint64) (uint64, error) {
	// lock uid
	c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE)
	ti := &TeamInfo{}
	// 先找一个无效的组id,相当于被删除的组
	if err := c.Find(bson.M{"uid": uid, "teamtype": TEAM_TYPE_INVALID}).One(ti); err != nil && err != mgo.ErrNotFound {
		return 0, errors.As(err, uid)
	}
	// 若没有无效组,查找已有最大组id
	if err := c.Find(bson.M{"uid": uid}).Sort("-teamid").One(ti); err != nil {
		if err == mgo.ErrNotFound {
			// 没有组,从1计数
			return uint64(int(uid)*MAX_NUM_TEAM + 1), nil
		}
		return 0, errors.As(err, uid)
	}
	// 判断是否超过用户组上限
	if int(ti.TeamId)%MAX_NUM_TEAM >= MAX_NUM_TEAM_USER {
		return 0, errors.New("user create team too many", uid)
	}

	return ti.TeamId + 1, nil
}