乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      redis 用戶登錄次數(shù)

       丶平上 2016-12-14
      1. <?php  
      2.   
      3. /** 
      4.  * 
      5.  * User: shikiliu 
      6.  * Date: 14-8-27 
      7.  */  
      8.   
      9. class ActiveDate  
      10. {  
      11.   
      12.   
      13.     private $redisConf = array('host' => 'localhost''port' => 6379);  
      14.   
      15.     private $redis = null;  
      16.   
      17.     private $userPrefix = 'user_active_';  
      18.   
      19.   
      20.     /** 
      21.      * 設(shè)置用戶某天登錄過 
      22.      */  
      23.     public function setActiveDate($userId$time = null)  
      24.     {  
      25.   
      26.         if (emptyempty($time)) {  
      27.   
      28.             $time = time();  
      29.         }  
      30.   
      31.         $redis = $this->getRedis();  
      32.   
      33.         $redis->setBit($this->userPrefix . $userId . '_' . date('Y-m'$time), intval(date('d'$time)) - 1, 1);  
      34.   
      35.         return true;  
      36.     }  
      37.   
      38.   
      39.     /** 
      40.      * 得到用戶本月登錄天數(shù) 
      41.      * redis >= 2.6.0 才可以 
      42.      */  
      43.     public function getActiveDatesCount($userId$time = null){  
      44.   
      45.         if (emptyempty($time)) {  
      46.   
      47.             $time = time();  
      48.         }  
      49.   
      50.         $redis = $this->getRedis();  
      51.   
      52.         return $redis->bitcount($this->userPrefix . $userId . '_' . date('Y-m'$time));  
      53.   
      54.     }  
      55.   
      56.   
      57.     /** 
      58.      * 得到用戶某月所有的登錄過日期 
      59.      */  
      60.     public function getActiveDates($userId$time = null)  
      61.     {  
      62.   
      63.   
      64.         $result = array();  
      65.   
      66.         if (emptyempty($time)) {  
      67.   
      68.             $time = time();  
      69.         }  
      70.   
      71.         $redis = $this->getRedis();  
      72.   
      73.         $strData = $redis->get($this->userPrefix . $userId . '_' . date('Y-m'$time));  
      74.   
      75.         if (emptyempty($strData)) {  
      76.             return $result;  
      77.         }  
      78.   
      79.         $monthFirstDay = mktime(0, 0, 0, date("m"$time), 1, date("Y"$time));  
      80.   
      81.         $maxDay = cal_days_in_month(CAL_GREGORIAN, date("m"$time), date("Y"$time));  
      82.   
      83.         $charData = unpack("C*"$strData);  
      84.   
      85.         for ($index = 1; $index <= count($charData); $index++) {  
      86.   
      87.             for ($bit = 0; $bit < 8; $bit++) {  
      88.   
      89.                 if ($charData[$index] & 1 << $bit) {  
      90.   
      91.                     //$intervalDay = ($index - 1) * 8 + 8-$bit;  
      92.                     $intervalDay = $index  * 8 -$bit;  
      93.                     //如果數(shù)據(jù)有大于當月最大天數(shù)的時候  
      94.                     if ($intervalDay > $maxDay) {  
      95.   
      96.                         return $result;  
      97.   
      98.                     }  
      99.   
      100.                     $result [] = date('Y-m-d'$monthFirstDay + ($intervalDay-1) * 86400);  
      101.   
      102.                 }  
      103.   
      104.             }  
      105.   
      106.         }  
      107.   
      108.         return $result;  
      109.   
      110.   
      111.     }  
      112.   
      113.   
      114.     /** 
      115.      *  redis連接 
      116.      */  
      117.     private function getRedis()  
      118.     {  
      119.   
      120.         if (emptyempty($this->redis)) {  
      121.   
      122.   
      123.             $redis = new Redis();  
      124.   
      125.             if (!$redis->connect($this->redisConf['host'], $this->redisConf['port'])) {  
      126.   
      127.                 throw new Exception("Error Redis Connect", 100);  
      128.   
      129.             }  
      130.   
      131.             $redis->select(3);  
      132.   
      133.             $this->redis = $redis;  
      134.   
      135.   
      136.         }  
      137.   
      138.         return $this->redis;  
      139.   
      140.     }  
      141.   
      142.   
      143. }  
      144.  

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多