search

Home  >  Q&A  >  body text

php - What is the role of memcache locking?

 /**
10 * Perform lock operation. What is the specific function of this function? Thanks
11 * @param [type] $lock_id
12 * @param integer $expire
13 */
14 public function Lock($lock_id,$expire=5){
15 $mkey = self::KEY_PREFIX.$lock_id;
16 for($i = 0; $i < 10; $i++){
17 $flag = false;
18 try{
19 $flag = $this->mc->add($mkey,'1',$expire);
20 }catch(Exception $e){
21 $flag = false;
22 //log
twenty three             }
24 if($flag){
25 return true;
26 }else{
27 //wait for 0.3 seconds
28 usleep(300000);
29 }
30}
31 return false;
32}
     
曾经蜡笔没有小新曾经蜡笔没有小新2821 days ago349

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 13:02:31

    /q/10...
    Here are the answers you want. The principles are almost the same

    reply
    0
  • Cancelreply