diff --git a/handler/video.go b/handler/video.go index f088f25..bed11ae 100644 --- a/handler/video.go +++ b/handler/video.go @@ -194,7 +194,7 @@ func DelayVideo(c *gin.Context) { } else { data := map[string]interface{}{"auth_id": int(id.(float64)), "method": "delay", "delay_time": time.Now().Format("2006-01-02 15:04:05"), "delay_day": delay_req.Day, "option": delay_req.Option, "id": delay_req.ID} str, _ := json.Marshal(data) - worker.PushRedisList(user.(string)+"-"+strconv.Itoa(int(id.(float64)))+"-option", string(str)) + service.SetVideoOption(user.(string)+"-"+strconv.Itoa(int(id.(float64)))+"-option", string(str)) c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": "延迟成功,影响记录:" + strconv.Itoa(cnt), "message": "success cnt:" + strconv.Itoa(cnt)}) } } else { diff --git a/service/videoService.go b/service/videoService.go index 19e9be7..508598e 100644 --- a/service/videoService.go +++ b/service/videoService.go @@ -69,7 +69,7 @@ func DeleteVideo(id, user int, tp string) int { if tp == "del_with_logic" { data := map[string]interface{}{"id": id, "auth_id": user, "delete_time": time.Now().Format("2006-01-02 15:04:05"), "method": "delete"} str, _ := json.Marshal(data) - worker.PushRedisList("user-"+strconv.Itoa(user)+"-option", string(str)) + SetVideoOption("user-"+strconv.Itoa(user)+"-option", string(str)) return dao.LogicDeleteVideoByID(id, user) } else if tp == "del_with_real" { return dao.DeleteVideoByID(id, user) @@ -130,3 +130,13 @@ func UpdateVideo(videoPath, videoName string, cameraID, videoID, authID, human, } return dao.UpdateVideo(videoPath, videoName, cameraID, videoID, authID, human, isDelete, createTime, endTime, fileSize) } + +func SetVideoOption(key string, value string) { + //查看list长度 + lens := worker.GetRedisListLen(key) + if lens > 100 { + //移除开头的元素 + worker.PopRedisList(key) + } + worker.PushRedisList(key, value) +} diff --git a/worker/redis.go b/worker/redis.go index 868d4ee..8eeea4c 100644 --- a/worker/redis.go +++ b/worker/redis.go @@ -205,6 +205,16 @@ func PushRedisList(key string, value string) bool { return true } +func GetRedisListLen(key string) int64 { + ctx := context.Background() + val, err := RedisClient.LLen(ctx, key).Result() + if err != nil { + fmt.Println("Error getting key: %v", err) + return 0 + } + return val +} + func PushRedisListWithExpire(key string, value string, expire time.Duration) bool { ctx := context.Background() err := RedisClient.RPush(ctx, key, value).Err()