wjy / locker
There is no license information available for the latest version (dev-master) of this package.
dev-master
2023-10-26 05:39 UTC
Requires
- lysice/hyperf-redis-lock: ^2.1
This package is not auto-updated.
Last update: 2024-11-08 04:59:16 UTC
README
composer require wjy/locker
使用
首先需要在程序内初始化redis
/**
* @var RedisLock
*/
protected $redis;
public function __construct(RedisFactory $redisFactory)
{
$this->redis = $redisFactory->get('default');
}
读写锁
public function lockA(ResponseInterface $response)
{
// 初始化RedisLock 参数:redis实例 锁名称 超时时间
$lock = new RedisLock($this->redis, 'lock', 4);
// 读锁
$res = $lock->readLock(4, function () {
return [456];
});
// 写锁
$res = $lock->writeLock(4, function() {
return [456];
})
return $response->json(['res' => $res]);
}