<?php
 namespace ModStart\Core\RateLimit; use ModStart\Core\Input\Request; use ModStart\Core\Util\RedisUtil; class RateLimitUtil { private static $ins = null; private static function instance() { if (null === self::$ins) { self::$ins = new RedisRateLimiter(); } return self::$ins; } public static function permit($key, $limit = 60, $window = 60) { return self::instance()->permit($key, $limit, $window); } public static function permitUrl($limit = 60, $window = 60) { return self::permit('RL:' . Request::path(), $limit, $window); } public static function permitBizUrl($biz, $limit = 60, $window = 60) { return self::permit('RL:' . $biz . ':' . Request::path(), $limit, $window); } public static function listVisitIps() { $ips = []; $redis = RedisUtil::client(); try { $keys = $redis->keys('F:V:*'); $fix = strlen('F:V:'); foreach ($keys as $key) { try { $ip = substr($key, $fix); $ips[$ip] = intval($redis->get($key)); } catch (\Exception $e) { } } } catch (\Exception $e) { } arsort($ips, SORT_NUMERIC); return $ips; } }