- 2
- 0
- 约4.65千字
- 约 4页
- 2026-06-09 发布于北京
- 举报
方案1
classLock
{
private$redis=;#redis对象
publicfunction__construct($host,$port=6379)
{
$this-redis=newRedis();
$this-redis-connect($host,$port);
}
/**
*@desc加锁方法
*
*@param$lockNamestring|锁的名字
*@param$timeoutint|锁的过期时间
*
*@return成功返回identifier/失败返回false
*/
publicfunctiongetLock($lockName,$timeout=2)
{
$identifier=uniqid();#获取唯一标识符
$timeout=ceil($timeout);#确保是整数
$end=time()+$timeout;
while(time()$e
原创力文档

文档评论(0)