/** * Lock the supplied Lockable. * * @param LockableInterface $lockable * @param int $timeout * * @return boolean */ public function lock(LockableInterface $lockable, $timeout = 1800) { $result = $this->client->setnx($lockable->getLockName(), true); if ($result == "OK") { $timeout = $this->client->expire($lockable->getLockName(), $timeout); } return $result == "OK" && $timeout == 1; }
/** * Release a lock. * * @param LockableInterface|null $lockable * * @return boolean */ public function release(LockableInterface $lockable = null) { return $this->client->del($lockable->getLockName()) >= 0; }