From 6ffabcdbcc184a6a7592549ae0b8894018fc67fd Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Tue, 25 Jun 2024 16:32:38 +0800 Subject: [PATCH] =?UTF-8?q?redis=E8=BE=93=E5=87=BAkey=20error,video=20quas?= =?UTF-8?q?h=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/video.go | 29 ++++++++++++----------------- worker/redis.go | 4 ++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/handler/video.go b/handler/video.go index 2641bae..4d6dd07 100644 --- a/handler/video.go +++ b/handler/video.go @@ -183,7 +183,7 @@ func DelayVideo(c *gin.Context) { if cnt == 0 { c.JSON(http.StatusOK, gin.H{"code": proto.OperationFailed, "data": "延迟失败数据", "message": "failed,cnt:" + strconv.Itoa(cnt)}) } else { - data := map[string]interface{}{"auth_id": int(id.(float64)), "delay_time": time.Now().Format("2006-01-02 15:04:05"), "delay_day": delay_req.Day, "option": delay_req.Option, "id": delay_req.ID} + 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)) c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": "延迟成功,影响记录:" + strconv.Itoa(cnt), "message": "success cnt:" + strconv.Itoa(cnt)}) @@ -200,7 +200,7 @@ func DeleteVideo(c *gin.Context) { if err := c.ShouldBind(&video_req); err == nil { res := service.DeleteVideo(video_req.ID, int(id.(float64))) if res != 0 { - data := map[string]interface{}{"id": video_req.ID, "auth_id": int(id.(float64)), "delete_time": time.Now().Format("2006-01-02 15:04:05")} + data := map[string]interface{}{"id": video_req.ID, "auth_id": int(id.(float64)), "delete_time": time.Now().Format("2006-01-02 15:04:05"), "method": "delete"} str, _ := json.Marshal(data) worker.PushRedisList(user.(string)+"-"+strconv.Itoa(int(id.(float64)))+"-option", string(str)) c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"}) @@ -213,25 +213,20 @@ func DeleteVideo(c *gin.Context) { } func QuashOption(c *gin.Context) { - var video_req VideoDelReq id, _ := c.Get("id") user, _ := c.Get("username") - if err := c.ShouldBind(&video_req); err == nil { - res := worker.PopRedisList(user.(string) + "-" + strconv.Itoa(int(id.(float64))) + "-option") - if res != "" { - var retrievedData map[string]interface{} - err2 := json.Unmarshal([]byte(res), &retrievedData) - if err2 != nil { - code, msg := service.QuashVideo(int(id.(float64)), retrievedData) - c.JSON(http.StatusOK, gin.H{"code": code, "message": msg, "data": msg}) - } else { - c.JSON(http.StatusOK, gin.H{"code": proto.ParameterError, "message": err2, "data": "2"}) - return - } + res := worker.PopRedisList(user.(string) + "-" + strconv.Itoa(int(id.(float64))) + "-option") + if res != "" { + var retrievedData map[string]interface{} + err2 := json.Unmarshal([]byte(res), &retrievedData) + if err2 != nil { + code, msg := service.QuashVideo(int(id.(float64)), retrievedData) + c.JSON(http.StatusOK, gin.H{"code": code, "message": msg, "data": msg}) } else { - c.JSON(http.StatusOK, gin.H{"code": proto.ParameterError, "message": "redis data not found", "data": "error"}) + c.JSON(http.StatusOK, gin.H{"code": proto.ParameterError, "message": err2, "data": "2"}) + return } } else { - c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"}) + c.JSON(http.StatusOK, gin.H{"code": proto.ParameterError, "message": "redis data not found", "data": "error"}) } } diff --git a/worker/redis.go b/worker/redis.go index c838ab7..64cc41d 100644 --- a/worker/redis.go +++ b/worker/redis.go @@ -149,7 +149,7 @@ func GetRedis(key string) string { ctx := context.Background() val, err := redisClient.Get(ctx, key).Result() // 从 Redis 读取键值, 如果键不存在则返回空字符串, 如果出现错误则返回错误 if err != nil { - fmt.Println("Error getting key: %v", err) + fmt.Println(key, " Error getting key: %v", err) return "" } return val @@ -160,7 +160,7 @@ func PopRedisList(key string) string { ctx := context.Background() val, err := redisClient.RPop(ctx, key).Result() // 从 Redis 读取键值, 如果键不存在则返回空字符串, 如果出现错误则返回错误 if err != nil { - fmt.Println("Error reading from Redis: %v", err) + fmt.Println(key, " Error reading from Redis: %v", err) return "" } return val