Beispiel #1
0
 /**
  * 处理已读消息
  */
 public function setReadAction()
 {
     echo date('Y-m-d H:i:s') . ' setRead is started!' . PHP_EOL;
     $queueKey = Yaf\Application::app()->getConfig()->redisKeys->setReadQueue;
     $readKeyPrefix = Yaf\Application::app()->getConfig()->redisKeys->readKeyPrefix;
     $redis = RedisFactory::instance('ims', true);
     while (true) {
         while ($userId = $redis->lPop($queueKey)) {
             $key = $readKeyPrefix . '_' . $userId;
             while ($messageId = $redis->lpop($key)) {
                 $messageModel = new MessageModel($userId);
                 $messageModel->setIsRead($messageId);
             }
             //推送未读消息变动通知
             $userModel = new UserModel();
             pushModel::unreadMessageNotice($userModel->getUnreadMessageList(true));
         }
         try {
             // 闲置时检查Redis连接
             $redis->ping();
         } catch (\Exception $e) {
             $redis = RedisFactory::instance('ims', true, true);
             //重连
         }
         sleep(1);
     }
     exit;
 }
Beispiel #2
0
 public function contactAction()
 {
     $message = $this->getRequest()->getParams();
     $redis = RedisFactory::instance('contact');
     $senderkey = ContactModel::CONTACT_KEY . '_' . $message['sender'] . '_' . $message['receiver'];
     $receiverkey = ContactModel::CONTACT_KEY . '_' . $message['receiver'] . '_' . $message['sender'];
     $respones = array();
     $respones['sender'] = $redis->hget($senderkey, 'lastMessageId') == $message['messageId'];
     $respones['receiver'] = $redis->hget($receiverkey, 'lastMessageId') == $message['messageId'];
     $this->getResponse()->setBody(json_encode($respones));
 }
Beispiel #3
0
 /**
  * 取得用户的Redis实例
  * @return redis
  */
 private function getUserRedis()
 {
     if (!$this->userRedis) {
         $this->userRedis = RedisFactory::instance('user');
     }
     return $this->userRedis;
 }
Beispiel #4
0
 /**
  * 取得联系人Redis实例
  */
 private function getContactRedis()
 {
     if (!$this->contactRedis) {
         $this->contactRedis = RedisFactory::instance('contact');
     }
     return $this->contactRedis;
 }
Beispiel #5
0
 /**
  * 取得缓存Redis实例
  */
 private function getCacheRedis()
 {
     if ($this->redis === null) {
         $this->redis = RedisFactory::instance('cache');
     }
     return $this->redis;
 }