mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
complains.php + confirm_resend.php add lock
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Nexus\Database;
|
||||
|
||||
use App\Exceptions\LockFailException;
|
||||
use Illuminate\Cache\LuaScripts;
|
||||
use Illuminate\Cache\RedisLock;
|
||||
|
||||
@@ -47,4 +48,17 @@ class NexusLock extends RedisLock
|
||||
return (bool) $this->redis->eval(LuaScripts::releaseLock(), [$this->name, $this->owner], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LockFailException
|
||||
*/
|
||||
public static function lockOrFail($name, $seconds, $owner = null): NexusLock
|
||||
{
|
||||
$lock = new self($name, $seconds, $owner);
|
||||
if (!$lock->acquire()) {
|
||||
do_log("$name failed to acquire lock", 'error');
|
||||
throw new LockFailException($name, $lock->owner());
|
||||
}
|
||||
return $lock;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user