修复获取key不交替进行,与imKey未及时删除

This commit is contained in:
junleea 2024-06-27 16:50:41 +08:00
parent f760b7a73f
commit f3314d2d1d
2 changed files with 16 additions and 2 deletions

View File

@ -61,10 +61,13 @@ func GetImKey(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"})
return
}
if retrievedData["from_user_id"] == id1 {
if int(retrievedData["from_user_id"].(float64)) == id1 {
if int(retrievedData["is_read"].(float64)) == 1 {
worker.DelRedis(redis_key)
}
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"})
return
} else {
} else if int(retrievedData["to_user_id"].(float64)) == id1 {
retrievedData["is_read"] = 1
str, _ := json.Marshal(retrievedData)
res3 := worker.SetRedisWithExpire(redis_key, string(str), time.Second*300)
@ -77,6 +80,9 @@ func GetImKey(c *gin.Context) {
return
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"})
return
} else {
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
return
}
}

View File

@ -176,6 +176,14 @@ func PopRedisListLeft(key string) string {
return val
}
func DelRedis(key string) {
ctx := context.Background()
err := redisClient.Del(ctx, key).Err()
if err != nil {
fmt.Println("Error deleting key: %v", err)
}
}
// push redis list from right
func PushRedisList(key string, value string) bool {
ctx := context.Background()