<?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 ftcy8; ftcy8: $zCpFL = new MySqlLock(config('env.DB_USERNAME'), config('env.DB_PASSWORD'), config('env.DB_HOST')); goto R_qll; kakmk: self::$instance = $A4S3g; goto WbMve; R_qll: $A4S3g = new MutexFabric('mysql', $zCpFL); goto kakmk; WbMve: } return self::$instance; } public static function acquire($L4owo, $WO3gU = 60) { if (RedisUtil::isEnable()) { goto EzL3w; n3aCR: return false; goto ouFxG; iciys: $IFAj4 = RedisUtil::get($dwwIV); goto YsV70; YsV70: if ($IFAj4 < time()) { RedisUtil::delete($dwwIV); return self::acquire($L4owo, $WO3gU); } goto n3aCR; qqwCU: if (RedisUtil::setnx($dwwIV, time() + $WO3gU)) { RedisUtil::expire($dwwIV, $WO3gU); return true; } goto iciys; EzL3w: $dwwIV = "Lock:{$L4owo}"; goto qqwCU; ouFxG: } else { if (self::instance()->get($L4owo)->acquireLock($WO3gU)) { return true; } } return false; } public static function release($L4owo) { if (RedisUtil::isEnable()) { $dwwIV = "Lock:{$L4owo}"; RedisUtil::delete($dwwIV); } else { self::instance()->get($L4owo)->releaseLock(); } } }