refactor(router): 优化消息存储逻辑,修复Redis键格式错误并移除过期时间
This commit is contained in:
parent
787e3775be
commit
79a41bc5ad
1 changed files with 22 additions and 15 deletions
|
@ -30,6 +30,8 @@ func Router(data map[string]interface{}) {
|
|||
sender := data["sender"].(map[string]interface{})
|
||||
role := sender["role"].(string)
|
||||
mid := data["message_id"].(float64)
|
||||
|
||||
// 将消息存入redis
|
||||
redisClient := tools.GetRedisClient()
|
||||
if redisClient != nil {
|
||||
var group_message GroupMessage
|
||||
|
@ -47,9 +49,9 @@ func Router(data map[string]interface{}) {
|
|||
return
|
||||
}
|
||||
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 {
|
||||
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)
|
||||
|
||||
} else {
|
||||
|
@ -77,7 +79,8 @@ func Router(data map[string]interface{}) {
|
|||
|
||||
}
|
||||
// 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:]
|
||||
parms := strings.Fields(raw_msg)
|
||||
|
@ -96,6 +99,10 @@ func Router(data map[string]interface{}) {
|
|||
} else {
|
||||
println("权限校验失败")
|
||||
}
|
||||
} else {
|
||||
// 实现触发器功能
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue