redis = new Redis(); $this->redis->connect('127.0.0.1', 6379); } public function isAllowed($ip) { $key = "rate_limit:{$ip}"; $current = $this->redis->get($key); if (!$current) { $this->redis->setex($key, $this->timeWindow, 1); return true; } if ($current >= $this->maxRequests) { return false; } $this->redis->incr($key); return true; } public function __destruct() { $this->redis->close(); } }