https://github.com/ledccn/webman_plugin_locker
Webman plugin ledc/locker
https://github.com/ledccn/webman_plugin_locker
Last synced: 5 days ago
JSON representation
Webman plugin ledc/locker
- Host: GitHub
- URL: https://github.com/ledccn/webman_plugin_locker
- Owner: ledccn
- Created: 2023-07-27T14:40:51.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2025-07-30T13:58:42.000Z (11 months ago)
- Last Synced: 2025-10-11T09:15:44.389Z (9 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## 介绍
symfony/lock for webman
在 webman 中简化使用业务锁功能
解决以下问题:
- 并发业务操作有时候需要锁来防止并发导致的数据插入或更新问题
- 单独使用 symfony/lock 时一般使用 $factory->createLock('key'),此时 key 是一个字符串,不利于后期维护或多处使用
## 安装
`compoer require ledc/locker`
## 使用
### 定义一个自己的 Locker 类
比如:`support\facade\Locker.php`,继承 `Ledc\Locker`
然后在类上方加入注释(用于代码提示),举例如下:
```php
acquire()) {
throw new \Exception('操作太频繁,请稍后再试');
}
try {
// 修改用户金额
} finally {
$lock->release();
}
return 'ok';
}
}
```