74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
|
|
import dotenv from 'dotenv';
|
|
import { createClient } from 'redis';
|
|
|
|
dotenv.config();
|
|
|
|
const prefix = process.env.PROJECT_PREFIX || 'default';
|
|
const initInfoKey = `${prefix}:InitInfo`;
|
|
|
|
const redis = createClient({
|
|
url: process.env.REDIS_URL || 'redis://localhost:6379'
|
|
});
|
|
|
|
async function clearOldPlatforms() {
|
|
try {
|
|
console.log('正在连接Redis...');
|
|
await redis.connect();
|
|
console.log('Redis连接成功\n');
|
|
|
|
const initInfoResult = await redis.json.get(initInfoKey, { path: '$' });
|
|
|
|
if (!initInfoResult || !initInfoResult[0]) {
|
|
console.log('未找到初始化信息');
|
|
return;
|
|
}
|
|
|
|
const initInfo = initInfoResult[0];
|
|
const targetAIGC = 'digitalHuman-v3';
|
|
|
|
console.log('检查平台数据...');
|
|
|
|
const multi = redis.multi();
|
|
const waitQueuesToDelete = [];
|
|
const validWaitQueues = [];
|
|
|
|
for (const [key, platform] of Object.entries(initInfo.platforms)) {
|
|
if (platform.AIGC !== targetAIGC) {
|
|
console.log(` 删除旧平台: ${key}`);
|
|
multi.json.del(initInfoKey, `$.platforms.${key}`);
|
|
waitQueuesToDelete.push(platform.waitQueue);
|
|
} else {
|
|
validWaitQueues.push(platform.waitQueue);
|
|
}
|
|
}
|
|
|
|
if (waitQueuesToDelete.length > 0) {
|
|
console.log(`\n删除旧平台的等待队列 (${waitQueuesToDelete.length} 个):`);
|
|
for (const queue of waitQueuesToDelete) {
|
|
console.log(` - ${queue}`);
|
|
await redis.del(queue);
|
|
}
|
|
}
|
|
|
|
multi.json.set(initInfoKey, '$.waitQueues', validWaitQueues);
|
|
|
|
await multi.exec();
|
|
|
|
console.log('\n✅ 旧平台数据已清空!');
|
|
console.log(` 保留的平台: ${targetAIGC}`);
|
|
console.log(` 保留的等待队列: ${validWaitQueues.length} 个`);
|
|
|
|
} catch (error) {
|
|
console.error('清空旧平台失败:', error);
|
|
} finally {
|
|
if (redis.isOpen) {
|
|
await redis.disconnect();
|
|
console.log('\nRedis连接已关闭');
|
|
}
|
|
process.exit();
|
|
}
|
|
}
|
|
|
|
clearOldPlatforms();
|