<?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 v7rAk; v6O2Z: self::$instance = $FYFvP; goto uP0aI; v7rAk: $mbzGK = new MySqlLock(config('env.DB_USERNAME'), config('env.DB_PASSWORD'), config('env.DB_HOST')); goto pbIim; pbIim: $FYFvP = new MutexFabric('mysql', $mbzGK); goto v6O2Z; uP0aI: } return self::$instance; } public static function acquire($XggBq, $dUHzU = 60) { if (RedisUtil::isEnable()) { goto UKckG; Vp_2v: if ($VJmY0 < time()) { RedisUtil::delete($GUcFO); return self::acquire($XggBq, $dUHzU); } goto Qi6U3; qZmOg: $VJmY0 = RedisUtil::get($GUcFO); goto Vp_2v; sWM7i: if (RedisUtil::setnx($GUcFO, time() + $dUHzU)) { RedisUtil::expire($GUcFO, $dUHzU); return true; } goto qZmOg; UKckG: $GUcFO = "Lock:{$XggBq}"; goto sWM7i; Qi6U3: return false; goto ZN_1S; ZN_1S: } else { if (self::instance()->get($XggBq)->acquireLock($dUHzU)) { return true; } } return false; } public static function release($XggBq) { if (RedisUtil::isEnable()) { $GUcFO = "Lock:{$XggBq}"; RedisUtil::delete($GUcFO); } else { self::instance()->get($XggBq)->releaseLock(); } } }