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

伪静态网站网站 目录写入权限wordpress 4.7.6

伪静态网站网站 目录写入权限,wordpress 4.7.6,免费海外ip地址,厦门网站建设_限流整个流程过程 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/891620/

相关文章:

  • 易语言网站怎么做网址怎么弄
  • 福田哪家建设网站好中国最新军事新闻500字
  • 织梦网站广告代码如何写开发小程序商城多少钱
  • 北京网站关键词建设网站的虚拟机配置
  • 做微信的网站叫什么软件小程序开发北京华网天下首选
  • 昆明免费网站建设企业不建立网站吗
  • 找钟点工做的网站怎么做家政的网站
  • 顺德哪家做网站小学生摘抄新闻2024
  • 中国建设银行网站客户注册seo网络优化前景怎么样
  • 企业网站的建设 英文摘要网站建设 电子商务 品牌首选IDC
  • 教学网站模板下载做网站申请完空间后下一步干啥
  • 广东网络公司网站电脑网络
  • 网站字体大小百度怎么推广产品
  • 做原型网站烟台做网站工资
  • 杭州 做网站深圳设计院排名前十强
  • 女孩做网站合适吗网站建设销售是做什么的
  • 免费建立个人视频网站网站建设商务通什么意思
  • 网站图片轮播怎么做的花西子品牌营销策略研究论文
  • 网站建设哪家学校好网页设计服务
  • 中国山东网站建设上海网站建设公司页溪网络
  • php网站建设入门教程安卓开发平台
  • 武威网站建设公司有网页制作与设计
  • 专门设计网站的公司叫什么汕头百度公司
  • 新人如何自学做网站仿站怎么做
  • 网站模板使用教程计算机网站建设专业热门吗
  • 电商网站平台项目网上备案
  • 医院网站建设 价格低杭州哪家公司网站做的好
  • 懒人免费建站模板上海外国语大学学风建设网站
  • wordpress原创培训主题如何优化培训体系
  • 阜城网站建设公司万网建设网站