POM.xml添加redis 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.0.1</version>
</dependency>
添加redis相关配置。本文档使用yml配置
spring:
redis:
host: xxx.xxx.xxx.xxx
port: 6379
password: xxxx
pool:
jedis:
#连接池最大连接数(使用负值表示没有限制)
max-active: 8
#连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: 1
#连接池中的最大空闲连接
max-idle: 8
#连接池中的最小空闲连接
min-idle: 0
java具体使用
@Autowired
private StringRedisTemplate stringRedisTemplate;
String key = "redisTemplateKey";