Merge pull request 'fix: 修复 TieredManager 创建 session 时 L1/L2 ID 不一致导致 Redis 写入失败的问题' (#131) from fix/redis-use into develop
Reviewed-on: http://8.161.227.145:3000/XEngineers/CamTalk/pulls/131
This commit was merged in pull request #131.
This commit is contained in:
@@ -47,7 +47,12 @@ func userSessKey(id string) string { return fmt.Sprintf("user:%s:sessions", id)
|
||||
|
||||
// Create 创建新会话。userID 为空表示匿名会话。
|
||||
func (m *RedisManager) Create(ctx context.Context, userID string, config models.SessionConfig) (string, error) {
|
||||
id := uuidNew()
|
||||
return m.CreateWithID(ctx, uuidNew(), userID, config)
|
||||
}
|
||||
|
||||
// CreateWithID 使用指定 ID 创建新会话。
|
||||
// 供 TieredManager 调用,确保 L1/L2 使用相同的 session ID。
|
||||
func (m *RedisManager) CreateWithID(ctx context.Context, id string, userID string, config models.SessionConfig) (string, error) {
|
||||
now := time.Now().UTC()
|
||||
|
||||
pipe := m.rdb.Pipeline()
|
||||
|
||||
@@ -127,9 +127,9 @@ func (m *TieredManager) Create(ctx context.Context, userID string, config models
|
||||
return "", err
|
||||
}
|
||||
|
||||
// L2: Redis(同步)
|
||||
// L2: Redis(同步),使用 L1 生成的 ID 保证一致性
|
||||
if m.isRedisOK() {
|
||||
if _, err := m.l2.Create(ctx, userID, config); err != nil {
|
||||
if _, err := m.l2.CreateWithID(ctx, id, userID, config); err != nil {
|
||||
logger.Log.Warnw("Redis Create failed, continuing without L2",
|
||||
"session", id, "error", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user