Download the PHP package msmm/hyperf-redis-lock without Composer
On this page you can find all versions of the php package msmm/hyperf-redis-lock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package hyperf-redis-lock
hyperf-redis-lock
一个简单的Redis分布式锁的实现 基于Hyperf框架。本扩展实现了基本的分布式锁,支持阻塞式分布式锁和非阻塞式分布式锁。
fork 自 Lysice/hyperf-redis-lock, 在其基础上支持
Hyperf ^3.1
原理
Redis
的命令为原子性 使用Redis
的set
即可保证业务的串行执行。
2.8
之前版本的Redis
不支持set
的ex
选项 因此只能使用 setnx+expire
的方式。 对应扩展1.0版本.
2.8
之后版本的Redis
可以直接使用 set
的nx+ex
选项。对应扩展2.*版本
因此 2.版本只支持2.8版本以后的Redis
1.版本支持所有版本的Redis
.
确认你的Redis版本 如果你的Redis低于 2.8版本 则set 命令不支持 ex选项 因此你需要安装1.0版本。
redis-server --version
安装
注意:请根据你的Redis
版本
使用
首先需要在程序内初始化你需要的 redis
-
非阻塞式锁(
互斥锁
、排它锁
) 该方法在尝试获取锁之后直接返回结果。若获取到锁则执行闭包后返回结果。否则返回false - 阻塞式锁(
自旋锁
) 该方法首先尝试获取锁,若获取失败 则每隔250毫秒获取一次 直到超时(等待时间超出本程序内锁的过期时间 则判定为超时)。如果锁获取成功 则执行闭包函数返回结果。 注意 若超时 则程序会抛出LockTimeoutException
超时异常。应用程序内需要自己捕获该异常以便处理超时情况的返回结果。 例子:
All versions of hyperf-redis-lock with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.1
hyperf/redis Version ^3.1
hyperf/stringable Version ^3.1
hyperf/support Version ^3.1
ext-redis Version *
hyperf/redis Version ^3.1
hyperf/stringable Version ^3.1
hyperf/support Version ^3.1
ext-redis Version *
The package msmm/hyperf-redis-lock contains the following files
Loading the files please wait ....