Redis+注解实现限流机制(IP、自定义等)

企业IT运维实录:批量部署银河麒麟V10-SP1,Ghost镜像与UKey激活实战 本文详细介绍了企业级银河麒麟V10-SP1操作系统的批量部署全流程,包括标准化镜像制作、自动化封装技术、网络化部署方案及UKey集群激活方案。通过实战案例和技术要点解析,帮助企业IT运维团队大幅提升部署效率,确保系统安全与稳定性。 阅读详情

简介

在项目的使用过程中,限流的场景是很多的,尤其是要提供接口给外部使用的时候,但是自己去封装的话,相对比较耗时。

本方式可以使用默认(方法),ip、自定义参数进行限流,根据时间和次数进行。

整合步骤

依赖

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.8.27</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.aviator</groupId>
            <artifactId>aviator</artifactId>
            <version>5.4.1</version>
            <scope>compile</scope>
        </dependency>

限流注解

package com.walker.ratelimiter.annotation;

import com.walker.ratelimiter.enums.LimitType;

import java.lang.annotation.*;

@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RateLimiter {

    /**
     * 限流key
     */
    String key() default "rate_limit";

    /**
     * 限流时间,单位秒
     */
    int time() default 60;

    /**
     * 限流次数
     */
    int count() default 50;

    /**
     * 限流类型
     */
    LimitType limitType() default LimitType.DEFAULT;

    /**
    * 自定义编码
     * 支持SPEL表达式
     * 如果使用多参数,则使用:分割
     *
    */
    String customerCode() default "";

    /**
     * 自定义编码分割符
     */
    String customerCodeSplit() default ":";
}

限流配置:获取限流lua脚本

package com.walker.ratelimiter.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.scripting.support.ResourceScriptSource;

@Configuration
public class RateLimitConfig {

    @Bean
    public DefaultRedisScript<Long> limitScript() {
        DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
        redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("lua/limit.lua")));
        redisScript.setResultType(Long.class);
        return redisScript;
    }

}

基础变量

package com.walker.ratelimiter.constants;

public interface BaseConstants {

    String COLON = ":";
}

枚举类型

package com.walker.ratelimiter.enums;

public enum LimitType {

    /**
     * 默认策略
     */
    DEFAULT,

    /**
     * 根据IP进行限流
     */
    IP,

    /**
    * 自定义
    */
    CUSTOME,

}

lua脚本

local key = KEYS[1]
local count = tonumber(ARGV[1])
local time = tonumber(ARGV[2])
local current = redis.call('get', key)
if current and tonumber(current) > count then
    return tonumber(current)
end
current = redis.call('incr', key)
if tonumber(current) == 1 then
    redis.call('expire', key, time)
end
return tonumber(current)

切面类

package com.walker.ratelimiter.aspect;

import cn.hutool.core.util.StrUtil;
import com.walker.ratelimiter.annotation.RateLimiter;
import com.walker.ratelimiter.constants.BaseConstants;
import com.walker.ratelimiter.enums.LimitType;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.context.expression.MethodBasedEvaluationContext;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.List;

@Slf4j
@Aspect
@Component
public class RateLimiterAspect {

    private final RedisTemplate redisTemplate;
    private final RedisScript<Long> limitScript;
    private SpelExpressionParser spelExpressionParser = new SpelExpressionParser();


    public RateLimiterAspect(RedisTemplate redisTemplate, RedisScript<Long> limitScript) {
        this.redisTemplate = redisTemplate;
        this.limitScript = limitScript;
    }

    @Around("@annotation(com.walker.ratelimiter.annotation.RateLimiter)")
    public Object doBefore(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();

        RateLimiter rateLimiter = methodSignature.getMethod().getAnnotation(RateLimiter.class);

        //判断该方法是否存在限流的注解
        if (null != rateLimiter) {
            //获得注解中的配置信息
            int count = rateLimiter.count();
            int time = rateLimiter.time();

            //调用getCombineKey()获得存入redis中的key   key -> 注解中配置的key前缀-ip地址-方法路径-方法名
            String combineKey = getCombineKey(rateLimiter, methodSignature, joinPoint);
            log.info("combineKey->,{}", combineKey);
            //将combineKey放入集合
            List<Object> keys = Collections.singletonList(combineKey);
            log.info("keys->", keys);
            try {
                //执行lua脚本获得返回值
                Long number = (Long) redisTemplate.execute(limitScript, keys, count, time);
                //如果返回null或者返回次数大于配置次数,则限制访问
                if (number == null || number.intValue() > count) {
                    throw new RuntimeException("访问过于频繁,请稍候再试");
                }
                log.info("限制请求'{}',当前请求'{}',缓存key'{}'", count, number.intValue(), combineKey);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RuntimeException("服务器限流异常,请稍候再试");
            }
        }

        return joinPoint.proceed();
    }

    /**
     * Gets combine key.
     *
     * @param rateLimiter the rate limiter
     * @param signature   the signature
     * @param joinPoint
     * @return the combine key
     */
    public String getCombineKey(RateLimiter rateLimiter, MethodSignature signature, ProceedingJoinPoint joinPoint) throws UnknownHostException {
        StringBuilder stringBuffer = new StringBuilder(rateLimiter.key());
//        ip限流
        if (rateLimiter.limitType() == LimitType.IP) {
            InetAddress ip = InetAddress.getLocalHost();
            log.info("获取ip地址为:{}", ip);
            String hostAddress = ip.getHostAddress();
            stringBuffer.append(hostAddress).append(BaseConstants.COLON);
//        自定义编码限流
        } else if (rateLimiter.limitType() == LimitType.CUSTOME) {
            if (StrUtil.isEmpty(rateLimiter.customerCode())) {
                throw new RuntimeException("自定义编码不能为空");
            }

            String customerCode = rateLimiter.customerCode();
            String split = rateLimiter.customerCodeSplit();
            String[] customerCodes = customerCode.split(split);
            for (String code : customerCodes) {
                ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
                EvaluationContext evaluationContext = new MethodBasedEvaluationContext(TypedValue.NULL, signature.getMethod(), joinPoint.getArgs(), parameterNameDiscoverer);
                Expression expression = spelExpressionParser.parseExpression(code);
                String resolvedCustomerCode =  String.valueOf(expression.getValue(evaluationContext));
                if(StrUtil.isEmpty(resolvedCustomerCode)){
                    throw new RuntimeException("自定义编码不能为空");
                }
                stringBuffer.append(BaseConstants.COLON).append(resolvedCustomerCode);
            }
        }
        Method method = signature.getMethod();
        Class<?> targetClass = method.getDeclaringClass();
        stringBuffer.append(BaseConstants.COLON).append(targetClass.getName()).append(BaseConstants.COLON).append(method.getName());
        return stringBuffer.toString();
    }


}


使用

  • 根据ip进行限流

limitType = LimitType.IP

  • 默认

limitType = LimitType.DEFAULT

  • 自定义参数限流

使用Spel表达式,从参数中获取自定义的code,然后60s限流5次

@RateLimiter(limitType = LimitType.CUSTOME,
             customerCode = "#form.appCode:#toUserInfo.userUid",
             count = 5,time = 60)
public Result<Boolean> message(ImSendMsgForm form, MissuUsers toUserInfo) {
    
}
深度测评:Accio Work——目前普通用户最友好的多 Agent 协同工具 摘要:Accio Work是阿里国际站推出的多Agent协同工具,通过借鉴古代"三省六部制"构建高效协作框架。该工具支持主流大模型,可配置专业Agent角色,实现40分钟内完成复杂产品PRD等高效协作。其亮点在于直观的UI设计和流程驱动机制,能强制各Agent从专业视角深度思考。虽然超长对话稳定性有待优化,但作为目前最用户友好的多Agent工具,显著降低了构建复杂AI团队的门槛,成为提升个人和小微企业生产力的利器。 阅读详情

相关推荐

Nexus7二代刷机教程(新手向)

该教程将使用lineageos(Android 11),同时借鉴了lineage官方的教程和songelf的教程。

2403_84391487的博客 5233

自定义注解+redis实现简单接口限流

/ 在 second 秒内,最大只能请求 maxCount 次 int second() default 1;@Target({ElementType.METHOD,ElementType.TYPE}) 指定这个注解可以用在方法或者类上(或者接口)@Retention(RetentionPolicy.RUNTIME) 指定注解的生命周期是运行时。首先要明确生命周期长度 SOURCE < CLASS < RUNTIME ,所以前者能作用的地方后者一定也能作用。

weixin_46666822的博客 382

ArcGIS新手必看:HWSD2土壤数据从下载到批量提取TIFF的完整流程

本文详细介绍了ArcGIS中HWSD2土壤数据的完整处理流程,从数据下载、预处理到批量提取TIFF文件。涵盖栅格属性表构建、属性数据连接及性能优化等关键步骤,帮助新手高效掌握HWSD2数据提取技术,提升地理信息数据处理效率。

ll5678的博客 1038

借助redis实现对IP限流

springboot项目中,借助redis实现对IP的限流

HUQWSYK的博客 724

从硬件到软件:深度解析D435i USB SCP overflow错误的根源与解决方案

本文深入解析Intel RealSense D435i相机在ROS环境下常见的'USB SCP overflow'错误,特别是与`control_transfer`相关的错误提示。从硬件配置到软件优化,详细介绍了如何通过调整USB接口、优化`rs_camera.launch`参数、更新固件驱动等方法解决数据传输溢出问题,提升设备稳定性和性能。

yy01234的博客 774

陀螺仪与加速度计的姿态融合——互补滤波

本篇文章我们来讲讲如何将陀螺仪和加速度计的数据结合起来,获取更准确的姿态数据,使用的是互补滤波的方法。

小白白学电子 2万+

Java实战:Spring Boot项目中如何利用Redis实现用户IP接口限流

本文将深入探讨如何在Spring Boot项目中借助Redis实现用户IP级别的接口限流策略,通过具体的代码示例,详细介绍其设计思路与实现过程。

oandy0的博客 1946

(RegionProposal Network)RPN网络结构及详解

RPN(RegionProposal Network)区域生成网络 Faster-RCNN的核心。在这里整理。 1.anchors。 特征可以看做一个尺度51*39的256通道图像,对于该图像的每一个位置,考虑9个可能的候选窗口:三种面积{128,256,512}×{128,256,512}×三种比例{1:1,1:2,2:1}{1:1,1:2,2:1}。这些候选窗口称为anchors...

凹酱的DEEP LEARNING 19万+

004-基于Redis自定义注解实现限流配置

🧑‍🎓 个人主页:Silence Lamb 📖 本章内容:【基于Redis自定义注解实现限流配置】

学习笔记 439

Qt C++ bridge模式(桥)

Bridge模式使得抽象和实现能够相对独立。 bridge.h #pragma once #include class CImplementor { public: virtual void operateImp() = 0; }; class CRectImplementor : public CImplementor { public: CR

thinkme2010的专栏 1894

《AI编程实战:深度学习模型改进与系统部署》,改进专栏目录和介绍

本专栏聚焦AI编程与深度学习实战,涵盖图像分类、目标检测、人脸识别、车牌识别、风格迁移、图像修复等10+计算机视觉任务,结合YOLO、Transformer、ViT等前沿模型,系统讲解从项目选题、数据处理、算法改进到Web/PyQt系统开发与模型部署的全流程。通过AI辅助编码与真实项目落地,助力零基础用户完成毕设、科研与论文写作,提供完整源码与持续更新内容,实现“一次订阅,永久学习”。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 3306

SpringBoot 项目使用 Redis 对用户 IP 进行接口限流

在下新建limit.lua-- 获取redis键-- 获取第一个参数(次数)-- 获取第二个参数(时间)-- 获取当前流量-- 如果current值存在,且值大于规定的次数,则拒绝放行(直接返回当前流量)end-- 如果值小于规定次数,或值不存在,则允许放行,当前流量数+1 (值不存在情况下,可以自增变为1)-- 如果是第一次进来,那么开始设置键的过期时间。end-- 返回当前流量@Slf4j@Aspect@Component@Autowired@Autowired。

m0_71777195的博客 437

YOLOv5 自定义模型 Android 部署完整指南

本文详细介绍了将YOLOv5模型部署到Android设备的完整流程,包含三个核心部分:首先验证官方模型测试,确保基础环境配置正确;随后进行模型转换,从PyTorch导出ONNX格式并优化,再转换为NCNN格式;最后在Android项目中集成自定义模型,包括文件替换、参数修改和代码适配。教程基于YOLOv5 6.1版本,使用NCNN框架进行移动端推理,涵盖了常见问题解决方案和关键配置要点,为开发者提供了从训练到部署的完整技术路线。

FJN110的博客 596

自定义注解,并编写一个aop,通过使用redis实现前台请求限流

主要作用是根据时间限制前台向后台的请求,通过aop切面实现方法之前检测请求次数 package cn.shangze.boot.common.annotation; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Reten...

FengRenYuanDeFZ的博客 539

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

SpringBoot实现限流注解

SpringBoot实现限流注解

胖胖爱吃肉~的博客 1207

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

ip限流功能的实现

IP防护功能的实现

王村头的博客 3283

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

10分钟上手!yudao-cloud限流降级实战:从接口保护到系统高可用

你是否遇到过接口被恶意频繁调用导致系统响应缓慢?是否担心突发流量冲垮服务器?本文将带你一文掌握yudao-cloud的限流降级机制,通过简单配置即可实现接口访问频率控制,为系统穿上"金钟罩"。读完本文你将学会: - 3种常用限流策略的配置方法 - 5分钟完成接口限流的实战步骤 - 如何通过降级策略应对极端流量 - 限流组件的工作原理与源码解析 ## 为什么需要限流降级? 在高并发场景下,系统面...

gitblog_01146的博客 399

SpringBoot接口防刷与限流实战:从原理到Redis+AOP实现

在分布式系统与高并发场景下,接口限流是保障服务稳定性的核心技术之一。其核心原理是通过控制单位时间内的请求数量,防止突发流量压垮系统资源。从技术价值看,有效的限流能够避免服务雪崩、保障核心业务,并提升系统整体的可用性与健壮性。常见的应用场景包括登录防暴力破解、秒杀活动、API调用配额管理等。为实现分布式环境下的精准控制,通常需借助Redis等高性能缓存存储计数状态,并结合AOP(面向切面编程)实现无侵入式的统一拦截。本文以SpringBoot项目为例,深入探讨了如何整合Redis与自定义注解,构建一套可应对接

weixin_33802505的博客 389

spring 根据redis实现的拦截效果

controller: @Delay(time = 2) <--重点是这个注解 @ApiOperation("用户换书开格子") @PostMapping("/user/inbooks/open/grid") public ResultData inbooksOpenGrid(@RequestBody InBookVO inBookVO) throws Excep...

weixin_43694038的博客 215

eladmin-mp接口安全双保险:@Limit限流注解与@AnonymousAccess匿名接口源码级解析

eladmin-mp 是一款基于 Spring Boot 2.7.18、MyBatis-Plus、Spring Security、Redis 与 Vue 的前后端分离后台管理系统,权限控制采用 RBAC。今天我们不聊增删改查,而是深入它的**接口安全双保险**:用 `@Limit` 限流注解挡住恶意刷接口的流量风暴,用 `@AnonymousAccess` 匿名接口注解优雅放行登录、验证码等免鉴权

gitblog_00225的博客 431

接口幂等性与限流(二)

自定义RateLimit注解@Target({/*** 限制时间段,单位为秒/*** 在限制时间段内允许的最大请求次数/*** 限流的key,支持SpEL表达式/*** 提示信息*/ String message() default "操作太频繁,请稍后再试";@Target({/*** 限制时间段,单位为秒/*** 在限制时间段内允许的最大请求次数/*** 限流的key,支持SpEL表达式/*** 提示信息。

weixin_54009596的博客 539

AOP实现登录,参数校验,接口限流

基于aop实现的登录校验,参数校验,接口限流

Quite_blue的博客 556

使用Spring Boot自定义注解 + AOP实现基于IP的接口限流和黑白名单

前言项目初始化自定义限流注解编写限流切面Controller中使用限流注解测试及思考结语在我们日常开发的项目中为了保证系统的稳定性,很多时候我们需要对系统做限流处理,它可以有效防止恶意请求对系统造成过载。网关限流NGINXZuul等 API 网关服务器端限流:服务端接口限流令牌桶算法:通过定期生成令牌放入桶中,请求需要消耗令牌才能通过熔断机制Hystrix等本文将详细介绍通过自定义注解和AOP(面向切面编程),实现基于IP的限流和黑白名单功能,包括如何使用Redis存储限流和黑名单信息。

Micro麦可乐的博客 1万+

Spring Boot通过自定义注解和Redis+Lua脚本实现接口限流

在我们日常开发的项目中为了保证系统的稳定性,很多时候我们需要对系统接口做限流处理,它可以有效防止恶意请求对系统造成过载。通过本文的步骤,我们将成功地在`Spring Boot`项目中结合`Redis`和`Lua`脚本实现了一个灵活高效的接口限流功能。通过`自定义注解`和`AOP`切面,可以方便地为不同的接口设置不同的限流策略

Micro麦可乐的博客 1万+

基于Redis+AOP+Lua脚本实现一个服务器限流机制

基于Redis+AOP+Lua脚本实现一个服务器限流机制

2303_80556719的博客 1197

【redis限流策略】redis实现限流的三种方式

其主要思想为模拟水桶中的水流量,加入一个固定的速率加入水,如果水桶满了,就拒绝后续的请求,否则按照固定的速率处理请求。因此,可使用Redis的有序集合数据类型,记录每次执行的时间和执行次数,用于在下一次添加令牌时,调整添加令牌的数量,以适应实际情况。令牌桶算法也属于流量控制算法,其主要思想为固定速率向令牌桶中添加令牌,一个请求需要获取令牌才能执行,当令牌桶中没有令牌时,请求将被拒绝。2.4 当请求加入List时,判断List的长度是否达到桶的最大限制,如果超过限制,就拒绝请求,否则可以正常处理。

qq_45248284的博客 1558
上一篇: 使用maven的方式创建Springboot项目
下一篇: Springboot使用Rabbitmq的延时队列+死信队列实现消息延期消费
WalkerShen
WalkerShen 优质创作者: Java技术领域 优质创作者: Java技术领域
博客等级 码龄8年 1万+粉丝 194原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WalkerShen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址