Initial commit: web_hghl_server

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 16:28:14 +08:00
co-authored by Claude Opus 4.7
commit 65fca60622
653 changed files with 135901 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package homeser
import (
"encoding/json"
"time"
"videoweb/app/api/proto"
"videoweb/pub/common/log"
"videoweb/pub/redis"
)
const (
appHomeCacheKey = "app:home:data"
appHomeCacheTTL = time.Minute * 5
)
// getHomeDataCache 读取 APP 首页 Redis 缓存,缓存异常时降级查库
func getHomeDataCache() *proto.DataResp {
cacheData, err1 := redis.Get(appHomeCacheKey)
if err1 != nil {
log.Warn("读取APP首页缓存失败", log.Any("cacheKey", appHomeCacheKey), log.E(err1))
return nil
}
if cacheData == nil || *cacheData == "" {
return nil
}
resp := &proto.DataResp{}
if err1 := json.Unmarshal([]byte(*cacheData), resp); err1 != nil {
log.Warn("解析APP首页缓存失败", log.Any("cacheKey", appHomeCacheKey), log.E(err1))
return nil
}
return resp
}
// setHomeDataCache 写入 APP 首页 Redis 缓存,缓存异常不影响主流程
func setHomeDataCache(resp proto.DataResp) {
bytes, err1 := json.Marshal(resp)
if err1 != nil {
log.Warn("序列化APP首页缓存失败", log.Any("cacheKey", appHomeCacheKey), log.E(err1))
return
}
if err1 := redis.Set(appHomeCacheKey, string(bytes), appHomeCacheTTL); err1 != nil {
log.Warn("写入APP首页缓存失败", log.Any("cacheKey", appHomeCacheKey), log.E(err1))
}
}