redis = $redis; } /** * Attempt to acquire the lock. * * @return bool */ public function acquire() { $result = $this->redis->setnx($this->name, 1); if ($result === 1 && $this->seconds > 0) { $this->redis->expire($this->name, $this->seconds); } return $result === 1; } /** * Release the lock. * * @return void */ public function release() { $this->redis->del($this->name); } }