修复获取key不交替进行,与imKey未及时删除
This commit is contained in:
parent
f760b7a73f
commit
f3314d2d1d
|
|
@ -61,10 +61,13 @@ func GetImKey(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"})
|
c.JSON(http.StatusOK, gin.H{"error": err2.Error(), "code": proto.OperationFailed, "message": "failed"})
|
||||||
return
|
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"})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"})
|
||||||
return
|
return
|
||||||
} else {
|
} else if int(retrievedData["to_user_id"].(float64)) == id1 {
|
||||||
retrievedData["is_read"] = 1
|
retrievedData["is_read"] = 1
|
||||||
str, _ := json.Marshal(retrievedData)
|
str, _ := json.Marshal(retrievedData)
|
||||||
res3 := worker.SetRedisWithExpire(redis_key, string(str), time.Second*300)
|
res3 := worker.SetRedisWithExpire(redis_key, string(str), time.Second*300)
|
||||||
|
|
@ -77,6 +80,9 @@ func GetImKey(c *gin.Context) {
|
||||||
return
|
return
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"})
|
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "data": retrievedData, "message": "success"})
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,14 @@ func PopRedisListLeft(key string) string {
|
||||||
return val
|
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
|
// push redis list from right
|
||||||
func PushRedisList(key string, value string) bool {
|
func PushRedisList(key string, value string) bool {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue