import redis from './redis/index.js'; import dotenv from 'dotenv'; import initQueue from './redis/initQueue.js'; dotenv.config(); const prefix = process.env.PROJECT_PREFIX || 'default'; const initInfoKey = `${prefix}:InitInfo`; async function checkRedisData() { try { console.log('正在连接Redis...'); // 连接Redis if (!redis.isOpen) { await redis.connect(); console.log('Redis连接成功'); } // 获取初始化信息 const initInfoResult = await redis.json.get(initInfoKey, { path: '$' }); console.log('\n初始化信息:', JSON.stringify(initInfoResult, null, 2)); // 处理Redis返回的数组格式数据 const initInfo = Array.isArray(initInfoResult) ? initInfoResult[0] : initInfoResult; // 获取平台信息 const platforms = initInfo?.platforms || {}; console.log('\n平台信息:', JSON.stringify(platforms, null, 2)); // 检查每个平台的配置 for (const [key, platform] of Object.entries(platforms)) { console.log(`\n平台 ${key} 详情:`); console.log(` AIGC: ${platform.AIGC}`); console.log(` platformName: ${platform.platformName}`); console.log(` WQtasks: ${platform.WQtasks}`); console.log(` PQtasks: ${platform.PQtasks}`); console.log(` MAX_CONCURRENT: ${platform.MAX_CONCURRENT}`); console.log(` waitQueue: ${platform.waitQueue}`); // 检查等待队列中的任务数 const waitQueueLength = await redis.lLen(platform.waitQueue); console.log(` 等待队列实际长度: ${waitQueueLength}`); // 获取等待队列中的任务ID const waitQueueTasks = await redis.lRange(platform.waitQueue, 0, -1); console.log(` 等待队列任务ID: ${waitQueueTasks}`); } // 检查各种队列状态 console.log('\n=== 队列状态检查 ==='); // 检查处理队列 const processPollingLength = await redis.lLen(initQueue.processPolling); console.log(`处理轮询队列(${initQueue.processPolling})长度: ${processPollingLength}`); const processCallbackLength = await redis.lLen(initQueue.processCallback); console.log(`处理回调队列(${initQueue.processCallback})长度: ${processCallbackLength}`); // 检查结果队列 const resultListLength = await redis.lLen(initQueue.resultList); console.log(`结果列表(${initQueue.resultList})长度: ${resultListLength}`); // 检查错误队列 const errorListLength = await redis.lLen(initQueue.errorList); console.log(`错误列表(${initQueue.errorList})长度: ${errorListLength}`); // 检查待发送消息队列 const pendingMessagesLength = await redis.lLen(initQueue.pendingMessages); console.log(`待发送消息队列(${initQueue.pendingMessages})长度: ${pendingMessagesLength}`); // 获取待发送消息详情 if (pendingMessagesLength > 0) { console.log('\n=== 待发送消息详情 ==='); const pendingMessageKeys = await redis.lRange(initQueue.pendingMessages, 0, -1); for (const messageKey of pendingMessageKeys) { try { const messageData = await redis.hGetAll(messageKey); if (messageData) { console.log(`消息 ${messageKey}:`); console.log(` backendId: ${messageData.backendId}`); console.log(` 消息内容: ${messageData.message?.slice(0, 100)}...`); console.log(` 时间戳: ${new Date(parseInt(messageData.timestamp || 0)).toLocaleString()}`); console.log(` 重试次数: ${messageData.retryCount || 0}`); } } catch (err) { console.error(`获取消息 ${messageKey} 失败:`, err); } } } // 检查回调队列 const callbackLength = await redis.lLen(initQueue.callback); console.log(`\n回调队列(${initQueue.callback})长度: ${callbackLength}`); } catch (error) { console.error('检查Redis数据失败:', error); } finally { // 断开Redis连接 if (redis.isOpen) { await redis.disconnect(); console.log('\nRedis连接已关闭'); } process.exit(); } } checkRedisData();