# 1分钟内出现100次某个行为，发报警

自然分钟很简单，不是自然分钟呢？

下面是伪代码：



```php
    function circuitBreaker($count, $limitTime = 60)
    {
        $redisKey = "test_redis";
        $currentTime = time();
        $length = $this->redis->lPush($redisKey, $currentTime);
        // 避免只入不出, 削个峰
        if ($length >= $count) {
            if ($length > $count * 1.5) {
                $this->redis->lTrim($redisKey, 0, $count - 1);
            }
            $previousTime = $this->redis->rPop($redisKey);
            if ($previousTime && ($currentTime - $previousTime <= $limitTime)) {
                return true;
            }
        }
        return false;
    }
```


