From 2a31e3faacf86ff7436d37b0a151d62dee9cf96e Mon Sep 17 00:00:00 2001 From: Cold <16419454+cold502@user.noreply.gitee.com> Date: Fri, 19 Dec 2025 17:57:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86go=20Httpserver.Run()=20=E6=8C=AA?= =?UTF-8?q?=E5=88=B0=20routeregister=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http/http.go | 2 +- redis/redis.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) 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 }