Пример #1
0
 public function actionRedisPushMessage()
 {
     /**
      * @var \Predis\Client $redis
      */
     $redis = DXUtil::redisClient();
     $user_func = function ($pubsub, $message) {
         $redis = DXUtil::redisClient();
         DXLog::consoleLog(json_encode($message));
         switch ($message->kind) {
             case 'subscribe':
                 DXLog::consoleLog("subscribed to {$message->channel}");
                 break;
             case 'message':
                 DXLog::consoleLog('received message: ' . json_encode($message));
                 $count = 0;
                 while (true) {
                     $count++;
                     DXLog::consoleLog($count);
                     if ($count > 10) {
                         DXLog::consoleLog('loop end');
                         break;
                     }
                     $payload = $redis->lpop(DXKey::getKeyOfPushMessageListWorking());
                     DXLog::consoleLog('pop: ' . $payload);
                     if (!$payload) {
                         DXLog::consoleLog('loop null break');
                         break;
                     }
                     $payload = @json_decode($payload, true);
                     DXLog::consoleLog($payload);
                 }
                 break;
         }
     };
     $redis->pubSubLoop(['subscribe' => DXKey::getKeyOfChannelPushMessage()], $user_func);
 }
Пример #2
0
 public function redis()
 {
     $redis = DXUtil::redisClient();
     return $redis;
 }