第11篇:redis基本使用
流程
依赖配置使用
1. 依赖
<dependency>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-starter-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons
</groupId>
<artifactId>commons-pool2
</artifactId>
<version>2.8.0
</version>
</dependency>
2. 配置
2.1 redis配置
spring.redis.database=0
spring.redis.host=localhost
spring.redis.port=6379
#spring.redis.password=
2.2 连接池配置
# 连接池最大连接数(使用负值表示没有限制) 默认 8
spring.redis.lettuce.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1
spring.redis.lettuce.pool.max-wait=-1
# 连接池中的最大空闲连接 默认 8
spring.redis.lettuce.pool.max-idle=8
# 连接池中的最小空闲连接 默认 0
spring.redis.lettuce.pool.min-idle=0
3. 使用
@Autowired
private RedisTemplate redisTemplate
;