diff --git a/handler/im.go b/handler/im.go index bda9e8e..5938f8b 100644 --- a/handler/im.go +++ b/handler/im.go @@ -66,13 +66,17 @@ func GetImKey(c *gin.Context) { return } else { retrievedData["is_read"] = 1 - res2 := worker.SetRedisWithExpire(redis_key+"_connection", retrievedData["im_session"].(string), time.Second*30) - if res2 == false { + str, _ := json.Marshal(retrievedData) + res3 := worker.SetRedisWithExpire(redis_key, string(str), time.Second*300) + res2 := worker.SetRedisWithExpire(redis_key+"_connection", retrievedData["im_session"].(string), time.Second*300) + if res2 == false || res3 == false { c.JSON(http.StatusOK, gin.H{"error": "set key failed", "code": proto.OperationFailed, "message": "failed"}) return } c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"}) return + c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"}) + return } } @@ -92,7 +96,7 @@ func GetImKey(c *gin.Context) { data["is_read"] = 0 str, _ := json.Marshal(data) //将key存入redis - res := worker.SetRedisWithExpire(redis_key, string(str), time.Second*30) + res := worker.SetRedisWithExpire(redis_key, string(str), time.Second*300) if res == false { c.JSON(http.StatusOK, gin.H{"error": "set key failed", "code": proto.OperationFailed, "message": "failed"}) return @@ -176,7 +180,7 @@ func SRMessage(c *gin.Context) { break } } - time.Sleep(time.Microsecond * 100) // 每100毫秒查询一次 + time.Sleep(time.Second * 1) // 每100毫秒查询一次 } else { clientsMux.Lock() delete(clients, ws) diff --git a/worker/redis.go b/worker/redis.go index 4d5bd37..cb011e0 100644 --- a/worker/redis.go +++ b/worker/redis.go @@ -171,7 +171,6 @@ func PopRedisListLeft(key string) string { ctx := context.Background() val, err := redisClient.LPop(ctx, key).Result() // 从 Redis 读取键值, 如果键不存在则返回空字符串, 如果出现错误则返回错误 if err != nil { - fmt.Println(key, " Error reading from Redis: %v", err) return "" } return val