<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ``` ~~~ <?php namespace app\common\service; use think\Exception; /** * Class RedisLimit * @package app\common\service * redis 簡單限流 */ class RedisLimit { /** * @var int */ static $oneITime = 60; // 單位時間 一分鐘 /** * @var int */ static $oneIMax = 50; // 一個用戶Ip一分鐘最多僅允許訪問訪問10次 /** * @var int */ static $platITime = 60; // 針對所有用戶,單位時間內允許訪問的最大次數 /** * @var int */ static $platIMax = 10; // 針對所有的用戶,該接口最多僅允許訪問N次 /** * Redis配置:IP */ const REDIS_CONFIG_HOST = '127.0.0.1'; /** * Redis配置:端口 */ const REDIS_CONFIG_PORT = 6379; const KEY='RT_DS8dsad845*/-sda'; /** * @return \think\response\Json * @throws Exception * 限制全局請求 */ public static function redis_lock_all_limit() { $redis = self::getRedisConn(); //.... 針對平臺全局鎖,用于限制單位時間內所有用戶訪問的次數 $platKey = md5(request()->url()); $platFlowCount = $redis->get($platKey);// 平臺訪問次數 if($platFlowCount){ if($platFlowCount >= self::$platIMax){ return json(['code'=>0,'msg'=>'超過訪問次數']); } } $redis->incr($platKey);// ++1 次訪問次數 !$platFlowCount && $redis->expire($platKey,self::$platITime); // 設置鎖的有效時間 return json(['code'=>1,'msg'=>'通過']); } /** * @param $mer_no * @param $oneITime * @param $oneIMax * @return bool * @throws Exception */ public static function redis_lock_single_limit($mer_no,$oneITime,$oneIMax) { $redis = self::getRedisConn(); // ... 針對單個商戶戶實現的訪問鎖 $key = md5($mer_no.':'.self::KEY); $userFlowCount = $redis->get($key); // 單個用戶訪問次數 if($userFlowCount){ if($userFlowCount >= $oneIMax){ return false; } } $redis->incr($key);// ++1 次訪問次數 !$userFlowCount && $redis->expire($key,$oneITime);// 設置鎖的有效時間 return true; } /** * @param string $strIp * @param int $intPort * @return \Redis * @throws Exception */ public static function getRedisConn($strIp = self::REDIS_CONFIG_HOST, $intPort = self::REDIS_CONFIG_PORT) { try { if (!extension_loaded('redis')) { throw new \BadFunctionCallException('not support: redis'); } $objRedis = new \Redis(); $objRedis->connect($strIp, $intPort); return $objRedis; }catch (Exception $exception){ throw new Exception($exception->getMessage()); } } } ~~~ ```
                  <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>

                              哎呀哎呀视频在线观看