<?php
require __DIR__ . '/../vendor/autoload.php';
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

try {
    $redis  = Illuminate\Support\Facades\Redis::connection();
    $result  = $redis->ping();
    $payload = is_object($result) && method_exists($result, 'getPayload') ? $result->getPayload() : $result;
    $ok      = ($payload === 'PONG' || $result === true || $result === 1);
    echo 'Redis:  ' . ($ok ? 'OK (PONG)' : 'UNEXPECTED: ' . var_export($result, true)) . PHP_EOL;
    echo 'Host:   ' . config('database.redis.default.host') . ':' . config('database.redis.default.port') . PHP_EOL;
    echo 'Client: ' . config('database.redis.client') . PHP_EOL;

    // Also check if the stats delta key has anything queued
    $depth = $redis->llen('artwork_stats:deltas');
    echo 'Delta queue depth (artwork_stats:deltas): ' . $depth . PHP_EOL;
} catch (Exception $e) {
    echo 'FAILED: ' . $e->getMessage() . PHP_EOL;
}
