refactor(router): 优化消息存储逻辑,修复Redis键格式错误并移除过期时间

This commit is contained in:
liyp 2024-10-20 16:29:19 +08:00
parent 787e3775be
commit 79a41bc5ad

View file

@ -30,6 +30,8 @@ func Router(data map[string]interface{}) {
sender := data["sender"].(map[string]interface{}) sender := data["sender"].(map[string]interface{})
role := sender["role"].(string) role := sender["role"].(string)
mid := data["message_id"].(float64) mid := data["message_id"].(float64)
// 将消息存入redis
redisClient := tools.GetRedisClient() redisClient := tools.GetRedisClient()
if redisClient != nil { if redisClient != nil {
var group_message GroupMessage var group_message GroupMessage
@ -47,9 +49,9 @@ func Router(data map[string]interface{}) {
return return
} }
key := fmt.Sprintf("group_message:%f:%f", gid, uid) key := fmt.Sprintf("group_message:%f:%f", gid, uid)
exists, err := tools.CheckKeyExists(fmt.Sprintf("group_message:%f:%f", gid, uid)) exists, err := tools.CheckKeyExists(fmt.Sprintf("group_message:%d:%d", int64(gid), int64(uid)))
if err != nil || !exists { if err != nil || !exists {
redisClient.RPush(context.Background(), key, jsonString, 7*24*time.Hour) redisClient.RPush(context.Background(), key, jsonString, 0)
// tools.SetValue(key, string(jsonString), 10*time.Second) // tools.SetValue(key, string(jsonString), 10*time.Second)
} else { } else {
@ -77,7 +79,8 @@ func Router(data map[string]interface{}) {
} }
// fmt.Println("raw_msg:", string(raw_msg)) // fmt.Println("raw_msg:", string(raw_msg))
if len(raw_msg) > 1 && string(raw_msg[0]) == prefix { if len(raw_msg) > 1 {
if string(raw_msg[0]) == prefix {
// 去除'!' // 去除'!'
raw_msg = raw_msg[1:] raw_msg = raw_msg[1:]
parms := strings.Fields(raw_msg) parms := strings.Fields(raw_msg)
@ -96,6 +99,10 @@ func Router(data map[string]interface{}) {
} else { } else {
println("权限校验失败") println("权限校验失败")
} }
} else {
// 实现触发器功能
}
} }
} }