use Illuminate\Support\Facades\Cache;
// CACHE_DRIVER=redis
$key = sprintf("carV2:panic_addSubsidy:%d", $value->getId());
$lock = Cache::lock($key, 20);
if (!$lock->get()) {
throw \ExceptionFactory::business(CodeMessageConstant::PANIC_ORDER_LOCKED);
}
try {
// ...
} catch (\Exception $e) {
$lock->release();
throw $e;
}
$lock->release();
参照 \Illuminate\Cache\RedisStore
\Illuminate\Cache\RedisLock