Beispiel #1
0
 /**
  * 获得小组成员-采用锁机制执行
  */
 public static function getGroupPlayer($playerUid)
 {
     $playerUid = (int) $playerUid;
     if (RedisUtil::lock(RedisUtil::LOCK_PLAYERS)) {
         $playerSize = RedisUtil::lLen(self::GAME_READY_PLAYERS);
         if ($playerSize >= 3) {
             $playerUids = array();
             //移除匹配状态
             $playerUids[] = RedisUtil::rPop(self::GAME_READY_PLAYERS);
             $playerUids[] = RedisUtil::rPop(self::GAME_READY_PLAYERS);
             self::rmReadyPlayer($playerUid);
             $playerUids[] = $playerUid;
             RedisUtil::unlock(RedisUtil::LOCK_PLAYERS);
             //添加游戏中状态
             foreach ($playerUids as $_uid) {
                 self::addInGamePlayer($_uid);
             }
             return $playerUids;
         }
     }
     RedisUtil::unlock(RedisUtil::LOCK_PLAYERS);
     return false;
 }