lock-lock.php

redis=$redis; } public function lock($key,$retry=2,$timeout=1,$ex=10){ $ok=false; $value=session_create_id(); while ( $retry-- ){ $ok=$this->redis->set($key,$value,[‘nx‘,‘ex‘=>$ex]); if($ok){ $this->lock_id[$key]=$value; break; } var_dump("等待获取锁"); sleep(1); //阻塞进程的 } return $ok; } public function unlock($key){ //直接删除key了 if(isset($this->lock_id[$key])){ $lock=$this->lock_id[$key]; if($this->redis->get($key) == $lock){ return $this->redis->delete($key); } } return false; } }

lock-lock.php

上一篇:启动容器失败:endpoint with name cop already exists in network host.


下一篇:从零学脚手架(三)---webpack属性详解