定制 snowio/magento2-lock 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

snowio/magento2-lock

最新稳定版本:v1.4.0

Composer 安装命令:

composer require snowio/magento2-lock

包简介

A Magento 2 module which provides a multi-server lock service

README 文档

README

Description

A Magento 2 module which provides a multi-server lock service. This allows developers to apply mutual exclusion locks to shared resources so that they are not accessed simultaneously.

Prerequisites

Installation

composer require snowio/magento2-lock
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:flush

Usage

The lock service can be accessed through dependency injection. Please refer the dependency injection section of the Magento DevDocs for more information on how to use dependency injection.

public boolean LockService::acquireLock(string $name, int $timeout)

Attempt to obtain a lock ####Parameters

  • $lockName : The lock identifier/name
  • $timeout : Lock timeout. A negative timeout implies an infinite timeout.

####Return Values A boolean indicating if the the lock was acquired.

public LockService::releaseLock($lockName)

Release the lock

Parameters

  • $lockName : The lock identifier/name

Example

namespace Vendor\Module\Model\Accessors;
class ResourceAccessor
{
    private $lockService;
    
    public function __construct(
        SnowIO\Lock\Api\LockService $lockService
    ) {
        $this->lockService = $lockService    
    }
    
    public function access($resource)
    {
        $lockName = //.. resource lock name
        
        //try acquire the lock
        if (!$this->lockService->acquireLock($lockName, 0)) {
            //Lock was not acquired ...
        }
        //Lock was acquired 
        
        try {
            // Process $resource 
        } finally {
            //release the lock
            $this->lockService->releaseLock($lockName);
        }
        
    }
}

Applications

License

This software is licensed under the MIT License. View the license

统计信息

  • 总下载量: 214.89k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 5
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-25