コード例 #1
0
ファイル: User.php プロジェクト: zhengyin/my-message
 /**
  * 取得整个未读消息列表
  * @param  $isGroup	是否进行分组
  * return array
  */
 public function getUnreadMessageList($isGroup = false)
 {
     $hKey = self::UNREAD_KEY . '_' . $this->userId;
     try {
         $data = $this->getUserRedis()->hgetall($hKey);
     } catch (\RedisException $e) {
         Log::error(self::LOG_DIR . '/unread', __METHOD__ . ':' . $e->getMessage());
         return array();
     }
     if (!$isGroup) {
         return empty($data) ? array() : $data;
     }
     $tmpArr = array();
     foreach ($data as $messageId => $sender) {
         $tmpArr[$sender][] = $messageId;
     }
     return $tmpArr;
 }
コード例 #2
0
ファイル: Cache.php プロジェクト: zhengyin/my-message
 /**
  * 缓存count或者更新count   
  * @param int $sender
  * @param int $receiver
  * @param array $updateData
  * @return boolean
  */
 private function cacheCount($sender, $receiver, $updateData = array())
 {
     try {
         //缓存往来消息总数
         $contactKey_1 = Cache::CONTACT_MESSAGE_COUNT . '_' . $sender . '_' . $receiver;
         if ($total = $this->getCacheRedis()->get($contactKey_1)) {
             if (isset($updateData['senderDeleted']) && $updateData['senderDeleted'] == 1) {
                 $this->getCacheRedis()->set($contactKey_1, $total - 1);
             } else {
                 $this->getCacheRedis()->incr($contactKey_1);
             }
         }
         $contactKey_2 = Cache::CONTACT_MESSAGE_COUNT . '_' . $receiver . '_' . $sender;
         if ($total = $this->getCacheRedis()->get($contactKey_2)) {
             if (isset($updateData['receiverDeleted']) && $updateData['receiverDeleted'] == 1) {
                 $this->getCacheRedis()->set($contactKey_2, $total - 1);
             } else {
                 $this->getCacheRedis()->incr($contactKey_2);
             }
         }
         //缓存收件箱
         $inBoxKey = Cache::INBOX_COUNT . '_' . $receiver;
         if ($total = $this->getCacheRedis()->get($inBoxKey)) {
             if (isset($updateData['receiverDeleted']) && $updateData['receiverDeleted'] == 1) {
                 $this->getCacheRedis()->set($inBoxKey, $total - 1);
             } else {
                 $this->getCacheRedis()->incr($inBoxKey);
             }
         }
         //缓存发件箱
         $outBoxKey = Cache::OUTBOX_COUNT . '_' . $sender;
         if ($total = $this->getCacheRedis()->get($outBoxKey)) {
             if (isset($updateData['senderDeleted']) && $updateData['senderDeleted'] == 1) {
                 $this->getCacheRedis()->set($outBoxKey, $total - 1);
             } else {
                 $this->getCacheRedis()->incr($outBoxKey);
             }
         }
     } catch (\RedisException $e) {
         Log::error(self::LOG_DIR . '/cache', $e->getMessage());
         return false;
     }
     return true;
 }