Exemple #1
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
}
Exemple #2
0
func RedisSetTeam(team *TeamInfo) error {
	userKey := fmt.Sprintf("%s%d", KEY_TEAM_INFO, team.TeamId)
	val, err := redis.RedisGet(userKey)
	if err != nil {
		return errors.As(err, *team)
	}

	var t TeamInfo
	err = json.Unmarshal([]byte(val), &t)
	if err != nil {
		return errors.As(err, *team)
	}

	if len(team.TeamName) > 1 {
		t.TeamName = team.TeamName
	}
	if len(team.CoreInfo) > 1 {
		t.CoreInfo = team.CoreInfo
	}

	if len(team.ExInfo) > 1 {
		t.ExInfo = team.ExInfo
	}

	b, err := json.Marshal(t)
	if err != nil {
		return errors.As(err, t)
	}
	userKey = fmt.Sprintf("%s%d", KEY_TEAM_INFO, team.TeamId)
	redis.RedisSet(userKey, string(b))

	//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
}
Exemple #3
0
func RedisDeleteTeamMember(tid, uid uint64) error {
	userKey := fmt.Sprintf("%s%d", SET_TEAM_MEMBER, tid)
	val := fmt.Sprintf("%d", uid)
	redis.SRem(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.SRem(userKey, val)

	return nil
}
Exemple #4
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
}