fix: 修复管理员会话键名冲突问题

- 恢复管理员会话管理的原始键名格式 session:${sessionId}
- 更改sticky会话映射使用独立前缀 sticky_session:${sessionHash}
- 避免sticky会话功能与管理后台会话冲突
- 添加sticky_session:*到cleanup清理模式
- 确保向后兼容性,管理后台功能正常

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
shaw
2025-07-15 18:43:32 +08:00
parent db8964d0f7
commit 8f7d3fcadf
2 changed files with 8 additions and 7 deletions

View File

@@ -407,18 +407,18 @@ class RedisClient {
// 🔐 会话管理(用于管理员登录等)
async setSession(sessionId, sessionData, ttl = 86400) {
const key = `admin_session:${sessionId}`;
const key = `session:${sessionId}`;
await this.client.hset(key, sessionData);
await this.client.expire(key, ttl);
}
async getSession(sessionId) {
const key = `admin_session:${sessionId}`;
const key = `session:${sessionId}`;
return await this.client.hgetall(key);
}
async deleteSession(sessionId) {
const key = `admin_session:${sessionId}`;
const key = `session:${sessionId}`;
return await this.client.del(key);
}
@@ -665,17 +665,17 @@ class RedisClient {
// 🔗 会话sticky映射管理
async setSessionAccountMapping(sessionHash, accountId, ttl = 3600) {
const key = `session:${sessionHash}`;
const key = `sticky_session:${sessionHash}`;
await this.client.set(key, accountId, 'EX', ttl);
}
async getSessionAccountMapping(sessionHash) {
const key = `session:${sessionHash}`;
const key = `sticky_session:${sessionHash}`;
return await this.client.get(key);
}
async deleteSessionAccountMapping(sessionHash) {
const key = `session:${sessionHash}`;
const key = `sticky_session:${sessionHash}`;
return await this.client.del(key);
}
@@ -686,6 +686,7 @@ class RedisClient {
'usage:daily:*',
'ratelimit:*',
'session:*',
'sticky_session:*',
'oauth:*'
];

View File

@@ -100,7 +100,7 @@ class SessionHelper {
* @returns {string} - Redis键名
*/
getSessionRedisKey(sessionHash) {
return `session:${sessionHash}`;
return `sticky_session:${sessionHash}`;
}
/**