<?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 mhkU6; wxEw0: $uG2OS = new MutexFabric('mysql', $mi91_); goto PE0Ly; PE0Ly: self::$instance = $uG2OS; goto w88PG; mhkU6: $mi91_ = new MySqlLock(config('env.DB_USERNAME'), config('env.DB_PASSWORD'), config('env.DB_HOST')); goto wxEw0; w88PG: } return self::$instance; } public static function acquire($glP3G, $PmvMF = 60) { if (RedisUtil::isEnable()) { goto Kjcic; kJPMa: return false; goto rxTa4; I6LYS: $LQZkU = RedisUtil::get($oMJcb); goto zbvXL; Kjcic: $oMJcb = "Lock:{$glP3G}"; goto V_wfK; zbvXL: if ($LQZkU < time()) { RedisUtil::delete($oMJcb); return self::acquire($glP3G, $PmvMF); } goto kJPMa; V_wfK: if (RedisUtil::setnx($oMJcb, time() + $PmvMF)) { RedisUtil::expire($oMJcb, $PmvMF); return true; } goto I6LYS; rxTa4: } else { if (self::instance()->get($glP3G)->acquireLock($PmvMF)) { return true; } } return false; } public static function release($glP3G) { if (RedisUtil::isEnable()) { $oMJcb = "Lock:{$glP3G}"; RedisUtil::delete($oMJcb); } else { self::instance()->get($glP3G)->releaseLock(); } } }