<?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 LuM8_; LuM8_: $mKlCF = new MySqlLock(config('env.DB_USERNAME'), config('env.DB_PASSWORD'), config('env.DB_HOST')); goto I0ptp; gYe63: self::$instance = $CPTQ1; goto FXw6i; I0ptp: $CPTQ1 = new MutexFabric('mysql', $mKlCF); goto gYe63; FXw6i: } return self::$instance; } public static function acquire($ZZMEd, $Cq6fQ = 60) { if (RedisUtil::isEnable()) { goto zZaj7; YYQ21: if (RedisUtil::setnx($l6tBV, time() + $Cq6fQ)) { RedisUtil::expire($l6tBV, $Cq6fQ); return true; } goto DEAum; MFxRt: return false; goto fTwmI; DEAum: $cWSeI = RedisUtil::get($l6tBV); goto ixj6R; zZaj7: $l6tBV = "Lock:{$ZZMEd}"; goto YYQ21; ixj6R: if ($cWSeI < time()) { RedisUtil::delete($l6tBV); return self::acquire($ZZMEd, $Cq6fQ); } goto MFxRt; fTwmI: } else { if (self::instance()->get($ZZMEd)->acquireLock($Cq6fQ)) { return true; } } return false; } public static function release($ZZMEd) { if (RedisUtil::isEnable()) { $l6tBV = "Lock:{$ZZMEd}"; RedisUtil::delete($l6tBV); } else { self::instance()->get($ZZMEd)->releaseLock(); } } }