예제 #1
0
 public function testCache()
 {
     $mc = \Memcache\Pool::instance();
     $cacheData = $mc->get('tt');
     $mc->set('tt', 123, 3);
     var_dump($cacheData);
 }
예제 #2
0
파일: Event.php 프로젝트: nangong92t/go_src
 /**
  * 通过消息类型统计消息条数.
  * 
  * @param integer $type 消息类型.
  * @param integer $uid  用户Id.
  * @param integer $pid  用户组privilege_group.
  * 
  * @return integer
  */
 private function getCountEventByTypeOfUid($type, $uid, $pid)
 {
     $redis = \Redis\Redis::getStorage();
     $memcache = \Memcache\Pool::instance();
     switch ($type) {
         case \Model\Event::EVENT_TYPE_ADD_SYSTEM_MSG:
         case \Model\Event::EVENT_TYPE_ADD_SYSTEM_USER:
         case \Model\Event::EVENT_TYPE_ADD_SYSTEM_GROUP:
             $userKey = $this->generateKey(self::REDIS_LAST_VIEW_TIME_USER, $uid);
             $lastViewTime = $redis->get($userKey);
             $timeKey = $this->generateKey(self::REDIS_SYSTEM_LAST_TIME, 'GLOBAL');
             $timeKeyMc = $this->generateKey($timeKey, self::MEMCACHE_SYSTEM_LAST_TIME_SUFFIX);
             if (!($lastSysTime = $memcache->get($timeKeyMc))) {
                 $lastSysTime = $redis->get($timeKey);
             }
             if ($lastSysTime <= $lastViewTime) {
                 $timeKey = $this->generateKey(self::REDIS_SYSTEM_LAST_TIME . 'GROUP_', $pid);
                 $timeKeyMc = $this->generateKey($timeKey, self::MEMCACHE_SYSTEM_LAST_TIME_SUFFIX);
                 if (!($lastGroupTime = $memcache->get($timeKeyMc))) {
                     $lastGroupTime = $redis->get($timeKey);
                 }
                 if ($lastGroupTime <= $lastViewTime) {
                     $timeKey = $this->generateKey(self::REDIS_SYSTEM_LAST_TIME . 'USER_', $uid);
                     $timeKeyMc = $this->generateKey($timeKey, self::MEMCACHE_SYSTEM_LAST_TIME_SUFFIX);
                     if (!($lastUserTime = $memcache->get($timeKeyMc))) {
                         $lastUserTime = $redis->get($timeKey);
                     }
                     if ($lastUserTime <= $lastViewTime) {
                         return 0;
                     }
                 }
             }
             return 1;
         case \Model\Event::EVENT_TYPE_ADD_REPORT_COMMENTS:
             $count = $redis->get($this->generateKey(self::REDIS_HASH_COMMENTS_COUNT, $uid));
             break;
         case \Model\Event::EVENT_TYPE_ADD_SYSTEM_USER:
             $count = $redis->get($this->generateKey(self::REDIS_SYSTEM_USER_COUNT, $uid));
             break;
         default:
             $cacheKey_type = $this->generateKey(self::REDIS_USER_EVENT_LIST, $type . "_" . $uid);
             $count = $redis->lSize($cacheKey_type);
             break;
     }
     return $count ? $count : 0;
 }