chore: cache username

This commit is contained in:
CaIon
2024-01-11 18:39:21 +08:00
parent 64e9e9cc20
commit f07b9f8ab2
4 changed files with 40 additions and 8 deletions

View File

@@ -68,6 +68,24 @@ func CacheGetUserGroup(id int) (group string, err error) {
return group, err
}
func CacheGetUsername(id int) (username string, err error) {
if !common.RedisEnabled {
return GetUsernameById(id)
}
username, err = common.RedisGet(fmt.Sprintf("user_name:%d", id))
if err != nil {
username, err = GetUserGroup(id)
if err != nil {
return "", err
}
err = common.RedisSet(fmt.Sprintf("user_name:%d", id), username, time.Duration(UserId2GroupCacheSeconds)*time.Second)
if err != nil {
common.SysError("Redis set user group error: " + err.Error())
}
}
return username, err
}
func CacheGetUserQuota(id int) (quota int, err error) {
if !common.RedisEnabled {
return GetUserQuota(id)