当前位置: 首页 > news >正文

西八里庄网站建设网站seo收录工具

西八里庄网站建设,网站seo收录工具,鲜花网网站开发的目标,国通快速建站限流整个流程过程 1.首先用户的请求进来,将用户ip和uri组成key,timestamp为value,放入zset 2. 更新当前key的缓存过期时间,这一步主要是为了定期清理掉冷数据,和上面我提到的常见错误设计2中的意义不同 3. 删除窗口之…

限流整个流程过程

1.首先用户的请求进来,将用户ip和uri组成key,timestamp为value,放入zset
2. 更新当前key的缓存过期时间,这一步主要是为了定期清理掉冷数据,和上面我提到的常见错误设计2中的意义不同
3. 删除窗口之外的数据记录
4. 统计当前窗口中的总记录数
5. 如果记录数大于阈值,则直接返回错误,否则正常处理用户请求

首先是定义一个注解,方便后续对不同接口使用不同的限制频率

package org.jeecg.common.aspect.annotation;import java.lang.annotation.*;/*** @Author xu* @create 2023/8/2 19*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RequestLimit {// 限制时间 单位:秒(默认值:一分钟)long period() default 60;// 允许请求的次数(默认值:5次)long count() default 5;}

切面AOP处理逻辑

package org.jeecg.common.aspect;import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.jeecg.common.aspect.annotation.RequestLimit;
import org.jeecg.common.exception.JeecgBootException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;/*** @Author xu* @create 2023/8/2 19*/
@Aspect
@Component
@Log4j2
public class RequestLimitAspect {@AutowiredRedisTemplate redisTemplate;// 切点@Pointcut("@annotation(requestLimit)")public void controllerAspect(RequestLimit requestLimit) {}@Around("controllerAspect(requestLimit)")public Object doAround(ProceedingJoinPoint joinPoint, RequestLimit requestLimit) throws Throwable {long period = requestLimit.period();long limitCount = requestLimit.count();Object[] args = joinPoint.getArgs();String ip = null;String url = null;for (Object arg : args) {if (arg instanceof HttpServletRequest) {HttpServletRequest request = (HttpServletRequest) arg;ip = request.getRemoteAddr();url = request.getRequestURI();break;  // 如果找到了符合条件的参数,可以选择跳出循环}}String key = "req_limit_".concat(url).concat(ip);ZSetOperations zSetOperations = redisTemplate.opsForZSet();long currentMs = System.currentTimeMillis();zSetOperations.add(key, currentMs, currentMs);redisTemplate.expire(key, period, TimeUnit.SECONDS);zSetOperations.removeRangeByScore(key, 0, currentMs - period * 1000);Long count = zSetOperations.zCard(key);if (count > limitCount) {log.error("接口拦截:{} 请求超过限制频率【{}次/{}s】,IP为{}", url, limitCount, period, ip);throw new JeecgBootException("请求太频繁,请稍后再试");}return joinPoint.proceed();}}

Controller层使用

	@AutoLog(value = "访客数据-添加")@RequestLimit(count = 2,period = 20)@ApiOperation(value="访客数据-添加", notes="访客数据-添加")@PostMapping(value = "/verifySave")public Result<?> verifySave(@RequestBody SysVisitantData sysVisitantData,HttpServletRequest request) {String ip = request.getRemoteAddr();String url = request.getRequestURI();return Result.OK("添加成功!");}
http://www.yayakq.cn/news/18987/

相关文章:

  • 网站续费查询昆明seo关键字推广
  • 做的网站底部应该标注什么意思网站建设家乡网页设计模板
  • 辽宁省营商环境建设监督局网站企业管理咨询机构
  • 数据库里建设好的网站为什么外网进不去网站html5技术可以制作网站吗
  • 建网站的费用是多少钱清风算法受影响的网站
  • 网站源码大全最新行业发展趋势
  • dedecms建站教程ui模板免费下载
  • 建站素材增城新闻头条今天
  • pos机网站建设方案长沙seo计费管理
  • 马鞍山做网站的门户网站有哪几个
  • 网站建设 报价单 doc佛山手机网站设计制作
  • 天津和平做网站网页游戏网站知乎
  • 网站模板50元手机软件开发培训班
  • 阿里云腾讯云网站建设外卖平台
  • 可口可乐公司的企业网站建设不要域名能建网站么
  • 温州网站建设 首选国鼎网络好域名解析错误是网络问题还是电脑问题
  • 做拍卖网站多少钱做网站的个人总结
  • 电子商务网站设计原理实践报告wordpress 链接按钮
  • wordpress后台登陆logowordpress伪静态优化
  • 要建设一个网站需要什么仿腾讯网站源码
  • 网站制作流程图制作ppt的软件app
  • 公司网站维护一般需要做什么网站开发如何使用API
  • 荆州市城市建设投资开发有限公司网站湖南湘江新区最新消息
  • 做淘宝保健品药品在哪个网站找素材企业在线
  • 新手如何搭建自己的网站网站app开发建设
  • 地税城市维护建设税网站是什么哈尔滨公司网站开发
  • 做网站还用注册商标吗广州php网站建设
  • 做技术网站在背景图django 微信小程序开发教程
  • 在线网站cms识别商城网站建设价格费用
  • 怎么制作网站登录j江苏省建设工程招投标网站