getProperty('connectionAttempted'); $connAttempted->setAccessible(true); $connAttempted->setValue(null, false); $clientProp = $ref->getProperty('client'); $clientProp->setAccessible(true); $clientProp->setValue(null, null); $res = Cache::set('test_cache_key', ['hello' => 'world'], 30); if ($res) { echo " ✅ Successfully set value in Redis.\n"; $val = Cache::get('test_cache_key'); if (isset($val['hello']) && $val['hello'] === 'world') { echo " ✅ Successfully retrieved value from Redis: " . json_encode($val) . "\n"; } else { echo " ❌ Failed to get correct value from Redis.\n"; } // Verify prefixing using a direct native Redis connection $nativeRedis = new \Redis(); try { if ($nativeRedis->connect(Env::get('REDIS_HOST', '127.0.0.1'), (int)Env::get('REDIS_PORT', 6379), 1.0)) { $nativeVal = $nativeRedis->get('nabeh:test_cache_key'); if ($nativeVal) { echo " ✅ Verified Prefixing: Native Redis key 'nabeh:test_cache_key' exists and has value: " . $nativeVal . "\n"; } else { echo " ❌ Prefixing test failed: key not found in native Redis.\n"; } $nativeRedis->close(); } } catch (\Exception $ex) { echo " ℹ️ Native verification connection skipped/failed: " . $ex->getMessage() . "\n"; } Cache::delete('test_cache_key'); } else { echo " ℹ️ Redis server is not running or unreachable (Fallback triggered, test completed successfully).\n"; } } catch (\Exception $e) { echo " Reflection or execution error: " . $e->getMessage() . "\n"; } } else { echo "\n2. Redis extension (phpredis) not installed. Native database fallback remains active.\n"; } echo "\n=== Redis Caching Tests Completed ===\n";