fwhappy/lock

There is no license information available for the latest version (v1.0.0) of this package.

Lock

Maintainers

Details

github.com/fwhappy/lock

Source

Issues

Installs: 22

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 1

Open Issues: 0

pkg:composer/fwhappy/lock

v1.0.0 2017-05-16 11:29 UTC

This package is not auto-updated.

Last update: 2025-10-26 07:42:42 UTC


README

概述

  • Lock包使用Redis来实现并发锁功能
  • 支持设置超时时间
  • 支持锁过期时间

使用

1、安装扩展

  • 支持composer安装

      {
        "require": {
          "php": ">=5.3.0",
          "fwhappy/lock": "^1.0"
        },
        "repositories": {
          "packagist": {
            "type": "composer",
            "url": "https://packagist.org"
          }
        }
      }
    
  • 或者

      composer require fwhappy/lock ^1.0
    
  • 也可以直接clone,放到项目中

      git clone git@github.com:fwhappy/lock.git
    

2、使用示例

require __DIR__ . '/vendor/autoload.php';

use Camry\Lock\Lock as Lock;

$redis = new Redis();
$redis->connect("127.0.0.1", 7480);
$redis->select(7);

$lock = new Lock($redis);
echo str_pad(" ", 4096);

if ($lock->acquire("TEST:LOCK:KEY", 10)) {
    echo "操作成功" . time();
    sleep(5);
    $lock->release("TEST:LOCK:KEY");
} else {
    echo "操作失败" . time();
}