Files
common/redis/types.go

40 lines
1.2 KiB
Go

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,
}
}