Пример #1
0
func TeamIds(uid int64) []int64 {
	key := fmt.Sprintf("u:tids:%d", uid)
	tids := []int64{}
	if err := cache.Get(key, &tids); err != nil {
		tids, err = Tids(uid)
		if err == nil {
			go cache.Set(key, tids, time.Hour)
		}
	}
	return tids
}
Пример #2
0
func AdminUserIds(tid int64) []int64 {
	key := fmt.Sprintf("t_admin:uids:%d", tid)
	uids := []int64{}
	if err := cache.Get(key, &uids); err != nil {
		uids, err = AdminUids(tid)
		if err == nil {
			go cache.Set(key, uids, time.Hour)
		}
	}
	return uids
}
Пример #3
0
func ReadUserIdByName(name string) int64 {
	if name == "" {
		return 0
	}

	key := fmt.Sprintf("user:id:%s", name)
	var id int64
	if err := cache.Get(key, &id); err != nil {
		id = SelectUserIdByName(name)
		if id > 0 {
			go cache.Set(key, id, time.Hour)
		}
	}

	return id
}
Пример #4
0
func ReadUserById(id int64) *User {
	if id <= 0 {
		return nil
	}

	key := fmt.Sprintf("user:obj:%d", id)
	var obj User
	if err := cache.Get(key, &obj); err != nil {
		objPtr := SelectUserById(id)
		if objPtr != nil {
			go cache.Set(key, objPtr, time.Hour)
		}
		return objPtr
	}

	return &obj
}
Пример #5
0
func ReadTeamById(id int64) *Team {
	if id <= 0 {
		return nil
	}

	key := fmt.Sprintf("team:obj:%d", id)
	var obj Team
	if err := cache.Get(key, &obj); err != nil {
		objPtr := SelectTeamById(id)
		if objPtr != nil {
			go cache.Set(key, objPtr, time.Hour)
		}
		return objPtr
	}

	return &obj
}
Пример #6
0
func ReadSessionBySig(sig string) *Session {
	if sig == "" {
		return nil
	}

	key := fmt.Sprintf("session:obj:%s", sig)
	var obj Session
	if err := cache.Get(key, &obj); err != nil {
		objPtr := SelectSessionBySig(sig)
		if objPtr != nil {
			go cache.Set(key, objPtr, time.Hour)
		}
		return objPtr
	}

	return &obj
}