示例#1
0
 protected function _bCheck($vObj, $sAction, $iSecond, $iMaxTimes, $iTimes, $bAlign, $iOffset)
 {
     list($timesfield, $ctimefield) = $this->_aGetObjFields($vObj, $sAction);
     if (0 == $iSecond) {
         $newtimes = $this->_oRedisDao->vHIncr($this->_sHashKey, $timesfield, $iTimes);
         assert(false !== $newtimes);
         return $newtimes <= $iMaxTimes;
     }
     $now = time();
     $info = $this->_aGet($vObj, $sAction);
     if (empty($info)) {
         $this->_oRedisDao->vHSet($this->_sHashKey, $ctimefield, $now);
         $newtimes = $this->_oRedisDao->vHIncr($this->_sHashKey, $timesfield, $iTimes);
         assert(false !== $newtimes);
         return $newtimes <= $iMaxTimes;
     }
     $start = parent::IGetStartTime($info['ctime'], $bAlign, $iSecond, $iOffset);
     if ($start + $iSecond > $now) {
         $newtimes = $this->_oRedisDao->vHIncr($this->_sHashKey, $timesfield, $iTimes);
         assert(false !== $newtimes);
         return $newtimes <= $iMaxTimes;
     }
     // 在临界时间点并发情况下可能会导致限制不严格的情况
     $this->_oRedisDao->vHSet($this->_sHashKey, $ctimefield, $now);
     $this->_oRedisDao->vHSet($this->_sHashKey, $timesfield, $iTimes);
     return true;
 }
示例#2
0
 protected function _bCheck($vObj, $sAction, $iSecond, $iMaxTimes, $iTimes, $bAlign, $iOffset)
 {
     $info = $this->_aGet($vObj, $sAction);
     if (empty($info)) {
         return $this->_bAdd($vObj, $sAction, $iMaxTimes, $iTimes);
     }
     if (0 == $iSecond) {
         return $this->_bUpdate($vObj, $sAction, $iMaxTimes, $iTimes);
     }
     $start = parent::IGetStartTime($info['ctime'], $bAlign, $iSecond, $iOffset);
     if ($start + $iSecond > time()) {
         return $this->_bUpdate($vObj, $sAction, $iMaxTimes, $iTimes);
     }
     return $this->_bReset($vObj, $sAction, $iMaxTimes, $iTimes, $info['ctime']);
 }