<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; use NinjaMutex\Lock\MySqlLock; use NinjaMutex\MutexFabric; class LockUtil { static $instance = null; private static function instance() { if (null === self::$instance) { goto PSC8J; PSC8J: $MWS35 = new MySqlLock(config('env.DB_USERNAME'), config('env.DB_PASSWORD'), config('env.DB_HOST')); goto lx17N; J0cfV: self::$instance = $YP_1D; goto ABfz9; lx17N: $YP_1D = new MutexFabric('mysql', $MWS35); goto J0cfV; ABfz9: } return self::$instance; } public static function acquire($f0dxO, $Qm3dU = 60) { if (RedisUtil::isEnable()) { goto QaRJF; uEOZA: if ($OmUAw < time()) { RedisUtil::delete($VFU9l); return self::acquire($f0dxO, $Qm3dU); } goto PKd7T; OskqD: $OmUAw = RedisUtil::get($VFU9l); goto uEOZA; PKd7T: return false; goto XtDpm; SgUzg: if (RedisUtil::setnx($VFU9l, time() + $Qm3dU)) { RedisUtil::expire($VFU9l, $Qm3dU); return true; } goto OskqD; QaRJF: $VFU9l = "Lock:{$f0dxO}"; goto SgUzg; XtDpm: } else { if (self::instance()->get($f0dxO)->acquireLock($Qm3dU)) { return true; } } return false; } public static function release($f0dxO) { if (RedisUtil::isEnable()) { $VFU9l = "Lock:{$f0dxO}"; RedisUtil::delete($VFU9l); } else { self::instance()->get($f0dxO)->releaseLock(); } } }