定制 kelunik/redis-mutex 二次开发

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

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

kelunik/redis-mutex

最新稳定版本:v0.2.2

Composer 安装命令:

composer require kelunik/redis-mutex

包简介

README 文档

README

Distributed mutual exclusion built upon the Amp concurrency framework and Redis.

Basic Example

$mutex = new Mutex(...);

// ...

try {
    $token = bin2hex(random_bytes(16));
    yield $mutex->lock($sessionId, $token);

    // Code here will only be executed in one client at a time.
    // If it takes longer than your specified TTL, you have to
    // renew the lock, see next example.

    yield $mutex->unlock($sessionId, $token);
} catch (MutexException $e) {
    // ...
}

Renew Example

$mutex = new Mutex(...);
$locks = [];

Loop::repeat(1000, function () use ($mutex, $locks) {
    foreach ($locks as $id => $token) {
        $mutex->renew($id, $token);
    }
});

// ...

try {
    $token = bin2hex(random_bytes(16));
    yield $mutex->lock($sessionId, $token);
    $locks[$sessionId] = $token;

    // Code here will only be executed in one client at a time.
    // Your lock will automatically be renewed by the reactor
    // repeat above. Don't do blocking things here (you should never
    // do that with Amp anyway), otherwise the reactor will not
    // be able to schedule the renewal.

    unset($locks[$sessionId]);
    yield $mutex->unlock($sessionId, $token);
} catch (MutexException $e) {
    // ...
}

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固