map预分配容量避免动态扩容,优化了返回值复用情况
This commit is contained in:
39
redis/types.go
Normal file
39
redis/types.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package redis
|
||||
|
||||
// SendStreamMessage 发送到 Redis Stream 的消息结构
|
||||
type SendStreamMessage struct {
|
||||
UserId string `json:"user_id"` // 用户ID
|
||||
Content string `json:"content"` // 消息内容
|
||||
Timestamp int64 `json:"timestamp"` // 时间戳(秒)
|
||||
MessageId string `json:"message_id"` // 消息唯一ID
|
||||
}
|
||||
|
||||
// ToMap 转换为 map[string]interface{} 用于 Stream 存储
|
||||
func (m *SendStreamMessage) ToMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"user_id": m.UserId,
|
||||
"content": m.Content,
|
||||
"timestamp": m.Timestamp,
|
||||
"message_id": m.MessageId,
|
||||
}
|
||||
}
|
||||
|
||||
// BatchStreamMessage 批量消息结构
|
||||
type BatchStreamMessage struct {
|
||||
UserId string `json:"user_id"` // 用户ID
|
||||
Content string `json:"content"` // 消息内容
|
||||
Timestamp int64 `json:"timestamp"` // 时间戳(秒)
|
||||
BatchId string `json:"batch_id"` // 批次ID
|
||||
Index int `json:"index"` // 批次内序号
|
||||
}
|
||||
|
||||
// ToMap 转换为 map[string]interface{} 用于 Stream 存储
|
||||
func (m *BatchStreamMessage) ToMap() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"user_id": m.UserId,
|
||||
"content": m.Content,
|
||||
"timestamp": m.Timestamp,
|
||||
"batch_id": m.BatchId,
|
||||
"index": m.Index,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user