Skip to content
forked from fwhappy/lock

Lock包使用Redis来实现并发锁功能

Notifications You must be signed in to change notification settings

jim61003/php-lock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lock

概述

  • 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 [email protected]: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();
}

About

Lock包使用Redis来实现并发锁功能

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%