# limiter-spring-boot-starter
**Repository Path**: tmq777/limiter-spring-boot-starter
## Basic Information
- **Project Name**: limiter-spring-boot-starter
- **Description**: 基于redis集群的令牌桶限流组件
- **Primary Language**: Java
- **License**: AGPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 4
- **Forks**: 1
- **Created**: 2022-03-09
- **Last Updated**: 2024-12-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: Java, SpringBoot
## README
# limiter-spring-boot-starter
#### 介绍
基于redis集群的令牌桶限流组件
#### 开发环境
- jdk 11.0.10
- SpringBoot 2.6.2
- Idea
#### 使用方法
1. 引入本jar包
```xml
cn.t.redis.limiter
limiter-spring-boot-starter
1.0.0
```
2. 配置`Redis`连接信息
```yaml
spring:
redis:
#host: localhost # 单点连接ip
#port: 18379 # # 单点连接端口
timeout: 6000 # 连接超时时间
password: your password
client-type: lettuce #指定连接工厂类型
cluster:
max-redirects: 3 # 获取失败 最大重定向次数
nodes: # 集群节点
- 127.0.0.1:7001
- 127.0.0.1:7002
- 127.0.0.1:7003
- 127.0.0.1:7004
- 127.0.0.1:7005
- 127.0.0.1:7006
lettuce: # lettuce连接池
pool:
max-active: 100 # 连接池最大连接数(使用负值表示没有限制)
max-idle: 20 # 最大空闲连接数
min-idle: 10 # 最小空闲连接数
max-wait: 1500 # 连接池最大阻塞等待时间(ms)(使用负值表示没有限制)
```
> stater中已经依赖了`spring-boot-starter-data-redis`
>
> 默认使用了`lettuce`,如果需要使用`jedis`,相关依赖也已经引入了。
其他依赖:
```xml
org.springframework.boot
spring-boot-starter-data-redis
redis.clients
jedis
org.apache.commons
commons-pool2
org.springframework.boot
spring-boot-starter-aop
```
自动配置类中默认配置了一个`RedisTemplate`, 如需要自定义则手动覆盖即可
```java
@Bean
@ConditionalOnMissingBean(RedisTemplate.class)
public RedisTemplate redisTemplate() {
RedisTemplate redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(this.connectionFactory);
// 定义Jackson2JsonRedisSerializer序列化对象
Jackson2JsonRedisSerializer