session缓存方法(tenantId+userId隔离)
This commit is contained in:
@@ -425,17 +425,17 @@ func GetRateLimit(ctx context.Context, key string) (count int64, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSessionCache 缓存 RAGFlow Session ID(租户+用户+方向隔离)
|
// SetSessionCache 缓存 RAGFlow Session ID(租户+用户隔离)
|
||||||
func SetSessionCache(ctx context.Context, tenantId, userId, chatId, sessionId string) error {
|
func SetSessionCache(ctx context.Context, tenantId, userId, sessionId string) error {
|
||||||
key := SessionLastActiveKeyPrefix + tenantId + ":" + userId + ":" + chatId + ":session_id"
|
key := SessionLastActiveKeyPrefix + tenantId + ":" + userId + ":session_id"
|
||||||
// SETEX key 7200 value (7200秒 = 2小时,与last_active保持一致)
|
// SETEX key 7200 value (7200秒 = 2小时,与last_active保持一致)
|
||||||
_, err := redisClient.Do(ctx, "SETEX", key, 7200, sessionId)
|
_, err := redisClient.Do(ctx, "SETEX", key, 7200, sessionId)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSessionCache 获取缓存的 RAGFlow Session ID(租户+用户+方向隔离)
|
// GetSessionCache 获取缓存的 RAGFlow Session ID(租户+用户隔离)
|
||||||
func GetSessionCache(ctx context.Context, tenantId, userId, chatId string) (string, error) {
|
func GetSessionCache(ctx context.Context, tenantId, userId string) (string, error) {
|
||||||
key := SessionLastActiveKeyPrefix + tenantId + ":" + userId + ":" + chatId + ":session_id"
|
key := SessionLastActiveKeyPrefix + tenantId + ":" + userId + ":session_id"
|
||||||
result, err := redisClient.Get(ctx, key)
|
result, err := redisClient.Get(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -448,9 +448,9 @@ func GetSessionCache(ctx context.Context, tenantId, userId, chatId string) (stri
|
|||||||
return result.String(), nil
|
return result.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DelSessionCache 删除缓存的 RAGFlow Session ID(归档时调用,租户+用户+方向隔离)
|
// DelSessionCache 删除缓存的 RAGFlow Session ID(归档时调用,租户+用户隔离)
|
||||||
func DelSessionCache(ctx context.Context, tenantId, userId, chatId string) error {
|
func DelSessionCache(ctx context.Context, tenantId, userId string) error {
|
||||||
key := SessionLastActiveKeyPrefix + tenantId + ":" + userId + ":" + chatId + ":session_id"
|
key := SessionLastActiveKeyPrefix + tenantId + ":" + userId + ":session_id"
|
||||||
_, err := redisClient.Del(ctx, key)
|
_, err := redisClient.Del(ctx, key)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user