argument('action'); switch ($action) { case 'redis': $this->testRedisConnection(); break; case 'delayqueue': $this->testDelayQueue(); break; case 'callback': $this->testCallback(); break; case 'all': default: $this->testRedisConnection(); $this->testDelayQueue(); $this->testCallback(); break; } } /** * 测试Redis连接 */ private function testRedisConnection() { $this->info('=== 测试Redis连接 ==='); try { $redis = Redis::client(); $this->info('✓ Redis连接成功'); $this->info('Redis类型: ' . get_class($redis)); // 测试基础操作 $testKey = 'test_urs_talent_' . time(); $redis->setex($testKey, 10, 'test_value'); $value = $redis->get($testKey); $this->info("✓ 测试键值: {$testKey} = {$value}"); // 清理测试数据 $redis->del($testKey); } catch (\Exception $e) { $this->error('✗ Redis连接失败: ' . $e->getMessage()); } } /** * 测试DelayQueue功能 */ private function testDelayQueue() { $this->info('=== 测试DelayQueue功能 ==='); try { // 准备测试数据 $callback = [UrsTalentUpstreamUpdateService::class, 'updateTalentLevel']; $runParam = [ 'referrer_id' => 999999, 'original_user_id' => 999998, 'level' => 2, 'trigger_time' => time() ]; $delaySeconds = 5; $this->info('回调: ' . implode('::', $callback)); $this->info('延时: ' . $delaySeconds . ' 秒'); $this->info('参数: ' . json_encode($runParam)); // 添加DelayQueue任务 $result = DelayQueueRedis::addQueue($callback, $runParam, $delaySeconds); if ($result === 0) { $this->warn('⚠ 任务已存在,跳过重复添加'); } else { $this->info('✓ DelayQueue任务添加成功'); } // 再次添加相同任务,测试防重复 $result2 = DelayQueueRedis::addQueue($callback, $runParam, $delaySeconds); if ($result2 === 0) { $this->info('✓ 防重复机制正常工作'); } else { $this->warn('⚠ 防重复机制可能有问题'); } } catch (\Exception $e) { $this->error('✗ DelayQueue测试失败: ' . $e->getMessage()); } } /** * 测试回调方法 */ private function testCallback() { $this->info('=== 测试回调方法 ==='); // 测试参数验证 $this->info('测试参数验证...'); // 空参数测试 $result = UrsTalentUpstreamUpdateService::updateTalentLevel([]); $this->info('空参数测试: ' . ($result ? '✓ 通过' : '✗ 失败(预期)')); // 不完整参数测试 $result = UrsTalentUpstreamUpdateService::updateTalentLevel([ 'referrer_id' => 999999 ]); $this->info('不完整参数测试: ' . ($result ? '✓ 通过' : '✗ 失败(预期)')); // 完整参数测试(用户不存在) $runParam = [ 'referrer_id' => 999999, 'original_user_id' => 999998, 'level' => 2, 'trigger_time' => time() ]; $this->info('测试完整参数(不存在的用户)...'); $result = UrsTalentUpstreamUpdateService::updateTalentLevel($runParam); $this->info('完整参数测试: ' . ($result ? '✓ 通过' : '✗ 失败(预期,用户不存在)')); // 测试批量更新 $this->info('测试批量更新...'); $results = UrsTalentUpstreamUpdateService::batchUpdateTalentLevels([999999, 999998]); $this->info('批量更新结果: ' . count($results) . ' 个用户处理完成'); } }