<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 訂閱模式 [TOC] 本文檔適用于4.2.13及以上版本,**4.2.12及以下版本訂閱模式存在BUG** ## 訂閱 與phpredis不同,subscribe/psubscribe為協程風格。 ~~~ $redis = new Swoole\Coroutine\Redis(); $redis->connect('127.0.0.1', 6379); if ($redis->subscribe(['channel1', 'channel2', 'channel3'])) // 或者使用psubscribe { while ($msg = $redis->recv()) { // msg是一個數組, 包含以下信息 // $type # 返回值的類型:顯示訂閱成功 // $name # 訂閱的頻道名字 或 來源頻道名字 // $info # 目前已訂閱的頻道數量 或 信息內容 list($type, $name, $info) = $msg; if ($type == 'subscribe') // 或psubscribe { // 頻道訂閱成功消息,訂閱幾個頻道就有幾條 } else if ($type == 'unsubscribe' && $info == 0) // 或punsubscribe { break; // 收到取消訂閱消息,并且剩余訂閱的頻道數為0,不再接收,結束循環 } else if ($type == 'message') // 若為psubscribe,此處為pmessage { // 打印來源頻道名字 var_dump($name); // 打印消息 var_dump($info); // 處理消息 // balabalaba.... if ($need_unsubscribe) // 某個情況下需要退訂 { $redis->unsubscribe(); // 繼續recv等待退訂完成 } } } } ~~~ ## 退訂 退訂使用unsubscribe/punsubscribe,`$redis->unsubscribe(['channel1'])` 此時`$redis->recv()`將會接收到一條取消訂閱消息,若取消訂閱多個頻道,則會收到多條。 **注意:退訂后務必繼續recv()到收到最后一條取消訂閱消息($msg\[2\] == 0),收到此條消息后,才會退出訂閱模式** ## En ~~~ $redis = new Swoole\Coroutine\Redis(); $redis->connect('127.0.0.1', 6379); if ($redis->subscribe(['channel1', 'channel2', 'channel3'])) // or use psubscribe { while ($msg = $redis->recv()) { // msg is an array containing the following information // $type # return type: show subscription success // $name # subscribed channel name or source channel name // $info # the number of channels or information content currently subscribed list($type, $name, $info) = $msg; if ($type == 'subscribe') // or psubscribe { // channel subscription success message } else if ($type == 'unsubscribe' && $info == 0) // or punsubscribe { break; // received the unsubscribe message, and the number of channels remaining for the subscription is 0, no longer received, break the loop } else if ($type == 'message') // if it's psubscribe,here is pmessage { // print source channel name var_dump($name); // print message var_dump($info); // handle messsage if ($need_unsubscribe) // in some cases, you need to unsubscribe { $redis->unsubscribe(); // continue recv to wait unsubscribe finished } } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看