60 lines
1.4 KiB
Markdown
60 lines
1.4 KiB
Markdown
## 简介
|
||
|
||
rate-limit-starter是基于redisson框架封装的限流框架,提供注解式@RateLimit限流。
|
||
|
||
全部特性:
|
||
|
||
- Spring Boot支持
|
||
- @RateLimit注解限流
|
||
- 多限流策略组合
|
||
- 可扩展限流方式,自己扩展IRateLimitHandler进行实现,默认是redisson
|
||
|
||
## 使用说明
|
||
|
||
**引入maven依赖**
|
||
|
||
注:需要引入redisson依赖 以及 hutool
|
||
|
||
```xml
|
||
|
||
<dependency>
|
||
<groupId>com.deepinnet</groupId>
|
||
<artifactId>rate-limit-starter</artifactId>
|
||
<version>0.0.1-SNAPSHOT</version><!--最新版本-->
|
||
</dependency>
|
||
```
|
||
|
||
**开启@EnableRateLimit**
|
||
|
||
```java
|
||
|
||
@SpringBootApplication
|
||
@EnableRateLimit
|
||
public class Application {
|
||
|
||
public static void main(String[] args) {
|
||
SpringApplication.run(PropertyTestApplication.class, args);
|
||
}
|
||
|
||
}
|
||
```
|
||
|
||
**需要限流的方法标记注解@RateLimit**
|
||
|
||
```java
|
||
@RateLimit(
|
||
// 唯一标示,支持SpEL表达式(可无),#name 为获取当前访问参数 name 内容
|
||
// key = "#code",
|
||
// 限定阈值,时间间隔 interval 范围内超过该数量会触发锁
|
||
count = 3,
|
||
// 限制间隔时长(可无,默认 3 分钟)例如 5s 五秒,6m 六分钟,7h 七小时,8d 八天
|
||
interval = "6m",
|
||
// 策略(可无) ip 为获取当前访问IP地址(内置策略)
|
||
strategy = {IpKeyGenerateStrategy.TYPE}
|
||
)
|
||
public void limit(){
|
||
|
||
}
|
||
```
|
||
|