<?php
class Send{
//可以选择列表类型来实现,记录每个ip每次访问的时间,一旦列表元素超过100,就判断时间最早的元素距离现在的时间是否小于1分钟,
//如果是则表明最近一分钟超频,否则就将现在的时间加入列表同时删除最早的时间元素
public $prefix = 'redis_';
public function test()
{
$key = $this->prefix.get_client_ip();
if (Redis::llen($key)) {
$count = Redis::llen($key);
if ($count > 3) {
$time = Redis::lrange($key, 0, 0);
if (time() - $time[0] < 60) {
return ['status'=>false,'msg=>'1分钟内只能发送3次'];
}else{
Redis::lrem($key, 1, $time[0]);
}
}
Redis::rpush($key, time());
} else {
Redis::rpush($key, time());
}
}
}