feat: 大规模性能优化 - Redis Pipeline 批量操作、索引系统、连接池优化

This commit is contained in:
SunSeekerX
2025-12-31 02:08:47 +08:00
parent a345812cd7
commit 584fa8c9c1
68 changed files with 6541 additions and 4536 deletions

View File

@@ -73,6 +73,7 @@ class BedrockAccountService {
const client = redis.getClientSafe()
await client.set(`bedrock_account:${accountId}`, JSON.stringify(accountData))
await redis.addToIndex('bedrock_account:index', accountId)
logger.info(`✅ 创建Bedrock账户成功 - ID: ${accountId}, 名称: ${name}, 区域: ${region}`)
@@ -127,11 +128,17 @@ class BedrockAccountService {
async getAllAccounts() {
try {
const client = redis.getClientSafe()
const keys = await client.keys('bedrock_account:*')
const accountIds = await redis.getAllIdsByIndex(
'bedrock_account:index',
'bedrock_account:*',
/^bedrock_account:(.+)$/
)
const keys = accountIds.map((id) => `bedrock_account:${id}`)
const accounts = []
const dataList = await redis.batchGetChunked(keys)
for (const key of keys) {
const accountData = await client.get(key)
for (let i = 0; i < keys.length; i++) {
const accountData = dataList[i]
if (accountData) {
const account = JSON.parse(accountData)
@@ -280,6 +287,7 @@ class BedrockAccountService {
const client = redis.getClientSafe()
await client.del(`bedrock_account:${accountId}`)
await redis.removeFromIndex('bedrock_account:index', accountId)
logger.info(`✅ 删除Bedrock账户成功 - ID: ${accountId}`)