git修复im传输问题,添加im过期时间
This commit is contained in:
parent
c2b3658f72
commit
11008cac8b
|
|
@ -169,7 +169,7 @@ func SRMessage(c *gin.Context) {
|
||||||
}
|
}
|
||||||
if msg.Type == "msg" {
|
if msg.Type == "msg" {
|
||||||
// 将消息发送到指定用户
|
// 将消息发送到指定用户
|
||||||
worker.PushRedisList(session+"_"+to_user_id, msg.Msg) //将消息存入redis
|
worker.PushRedisListWithExpire(session+"_"+to_user_id, msg.Msg, time.Hour*1) //将消息存入redis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(ws, res, to_user_id)
|
}(ws, res, to_user_id)
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,21 @@ func PushRedisList(key string, value string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PushRedisListWithExpire(key string, value string, expire time.Duration) bool {
|
||||||
|
ctx := context.Background()
|
||||||
|
err := redisClient.RPush(ctx, key, value).Err()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error setting key: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
err = redisClient.Expire(ctx, key, expire).Err()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error setting key: %v", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// delete redis key
|
// delete redis key
|
||||||
func delRedis(key string) {
|
func delRedis(key string) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue