Merge branch 'refs/heads/feat-conf-redis'
This commit is contained in:
commit
edef1fd7e0
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue