<?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 TXPL7; xqVmY: $HyetP = new MutexFabric('mysql', $LXtOP); goto Lqzbo; TXPL7: $LXtOP = new MySqlLock(config('env.DB_USERNAME'), config('env.DB_PASSWORD'), config('env.DB_HOST')); goto xqVmY; Lqzbo: self::$instance = $HyetP; goto mvU7C; mvU7C: } return self::$instance; } public static function acquire($L1g9F, $CG1sb = 60) { if (RedisUtil::isEnable()) { goto Jy7ia; Cpa40: if ($ef7Qp < time()) { RedisUtil::delete($rvTrU); return self::acquire($L1g9F, $CG1sb); } goto Rne8P; PokYQ: if (RedisUtil::setnx($rvTrU, time() + $CG1sb)) { RedisUtil::expire($rvTrU, $CG1sb); return true; } goto J02l9; J02l9: $ef7Qp = RedisUtil::get($rvTrU); goto Cpa40; Jy7ia: $rvTrU = "Lock:{$L1g9F}"; goto PokYQ; Rne8P: return false; goto JX0vt; JX0vt: } else { if (self::instance()->get($L1g9F)->acquireLock($CG1sb)) { return true; } } return false; } public static function release($L1g9F) { if (RedisUtil::isEnable()) { $rvTrU = "Lock:{$L1g9F}"; RedisUtil::delete($rvTrU); } else { self::instance()->get($L1g9F)->releaseLock(); } } }