<?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 Br32d; Br32d: $rljo1 = new MySqlLock(config('env.DB_USERNAME'), config('env.DB_PASSWORD'), config('env.DB_HOST')); goto KVrxP; KVrxP: $gDysi = new MutexFabric('mysql', $rljo1); goto M0AEQ; M0AEQ: self::$instance = $gDysi; goto Zpood; Zpood: } return self::$instance; } public static function acquire($c6VKG, $t33Sv = 60) { if (RedisUtil::isEnable()) { goto p7WRl; w243a: if ($Qq2ve < time()) { RedisUtil::delete($HQKqq); return self::acquire($c6VKG, $t33Sv); } goto qzTWZ; qzTWZ: return false; goto QvS40; hApDF: if (RedisUtil::setnx($HQKqq, time() + $t33Sv)) { RedisUtil::expire($HQKqq, $t33Sv); return true; } goto OLAXO; OLAXO: $Qq2ve = RedisUtil::get($HQKqq); goto w243a; p7WRl: $HQKqq = "Lock:{$c6VKG}"; goto hApDF; QvS40: } else { if (self::instance()->get($c6VKG)->acquireLock($t33Sv)) { return true; } } return false; } public static function release($c6VKG) { if (RedisUtil::isEnable()) { $HQKqq = "Lock:{$c6VKG}"; RedisUtil::delete($HQKqq); } else { self::instance()->get($c6VKG)->releaseLock(); } } }