public ResponseResult login(LoginDto loginDto) { /**\ * 如果用户名与密码存在则进行正常登录 */ if(StringUtils.isNotBlank(loginDto.getPhone()) && StringUtils.isNotBlank(loginDto.getPassword())){ //1.查看是否达到限流阈值(5分钟之内3次请求) //先对5分钟之前推积的无用数据进行清除 long timestamp = System.currentTimeMillis() - (5 * 60 * 1000); // 五分钟前的时间戳 cacheService.zRemoveRangeByScore("User:Login:"+loginDto.getPhone(),Double.NEGATIVE_INFINITY,timestamp); System.err.println("当前五分钟之前的时间戳"+timestamp); //查询5分钟之内的数据 Set<String> strings = cacheService.zReverseRangeByScore("User:Login:" + loginDto.getPhone(), timestamp, new Date().getTime()); if(strings.size()<3){ cacheService.zAdd("User:Login:"+loginDto.getPhone(), String.valueOf(new Date().getTime()),new Date().getTime()); }else{ return ResponseResult.errorResult(AppHttpCodeEnum.NO_OPERATOR_AUTH,"当前登录次数过多,请于一分钟后重试"); }
}