diff --git a/http/http.go b/http/http.go index 09f2641..67bdc51 100644 --- a/http/http.go +++ b/http/http.go @@ -44,7 +44,6 @@ func init() { Httpserver.SetOpenApiPath("/api.json") Httpserver.SetDumpRouterMap(true) //关闭打印路由注册信息 Httpserver.BindMiddlewareDefault(ghttp.MiddlewareHandlerResponse) - go Httpserver.Run() Httpclient.SetDiscovery(gsvc.GetRegistry()) } func RouteRegister(controllers []interface{}) { @@ -59,6 +58,7 @@ func RouteRegister(controllers []interface{}) { group.Bind(t) }) } + go Httpserver.Run() } func doRequest(ctx context.Context, method string, url string, target any, data ...any) (err error) { err = utils.ValidStructPtr(target) diff --git a/redis/redis.go b/redis/redis.go index 072fb1b..8d393b2 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -567,9 +567,9 @@ const ( ConversationCacheExpireSeconds = 600 ) -// CacheConversation 缓存单条对话到Redis List -func CacheConversation(ctx context.Context, userId, platform string, data []byte) error { - key := ConversationCacheKeyPrefix + userId + "_" + platform +// CacheConversation 缓存单条对话到Redis List(按sessionId存储) +func CacheConversation(ctx context.Context, sessionId string, data []byte) error { + key := ConversationCacheKeyPrefix + sessionId _, err := redisClient.Do(ctx, "RPUSH", key, string(data)) if err != nil { return err @@ -578,9 +578,9 @@ func CacheConversation(ctx context.Context, userId, platform string, data []byte return err } -// GetCachedConversations 获取缓存的对话列表并清空 -func GetCachedConversations(ctx context.Context, userId, platform string) (list []string, err error) { - key := ConversationCacheKeyPrefix + userId + "_" + platform +// GetCachedConversations 获取缓存的对话列表并清空(按sessionId查询) +func GetCachedConversations(ctx context.Context, sessionId string) (list []string, err error) { + key := ConversationCacheKeyPrefix + sessionId result, err := redisClient.Do(ctx, "LRANGE", key, 0, -1) if err != nil { return @@ -594,9 +594,9 @@ func GetCachedConversations(ctx context.Context, userId, platform string) (list return } -// GetCachedConversationCount 获取缓存的对话数量 -func GetCachedConversationCount(ctx context.Context, userId, platform string) (count int64, err error) { - key := ConversationCacheKeyPrefix + userId + "_" + platform +// GetCachedConversationCount 获取缓存的对话数量(按sessionId查询) +func GetCachedConversationCount(ctx context.Context, sessionId string) (count int64, err error) { + key := ConversationCacheKeyPrefix + sessionId result, err := redisClient.Do(ctx, "LLEN", key) if err != nil { return @@ -604,9 +604,9 @@ func GetCachedConversationCount(ctx context.Context, userId, platform string) (c return result.Int64(), nil } -// ClearCachedConversations 清空对话缓存(归档时调用) -func ClearCachedConversations(ctx context.Context, userId, platform string) error { - key := ConversationCacheKeyPrefix + userId + "_" + platform +// ClearCachedConversations 清空对话缓存(归档时调用,按sessionId) +func ClearCachedConversations(ctx context.Context, sessionId string) error { + key := ConversationCacheKeyPrefix + sessionId _, err := redisClient.Del(ctx, key) return err }