1. 官方介紹
2. 整合過程
1. 添加依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2. 配置相關配置文件
# ========== redis基礎配置 ============
spring.redis.database=0
spring.redis.host=127.0.0.1
spring.redis.password=password
spring.redis.port=6379
## 連接超時時間 丹喂 ms(毫秒)
spring.redis.timeout=3000
# ========== redis線程池設置 ============
# 連接池中的最大空閒連接,默認值是8
spring.redis.pool.max-idle=200
# 連接池中最小的空閒連接,默認值是0
spring.redis.pool.min-idle=200
# 如果賦值爲-1,則表示不限制;pool已經分配了maxActive個jedis實例,則此時pool的狀態爲exhausted(耗盡)
spring.redis.pool.max-active=2000
# 等待可用連接的最大時間,單位毫秒,默認值爲-1.表示永不超時
spring.redis.pool.max-wait=1000
3. 簡單使用Redis
-
注入
@Autowired private StringRedisTemplate redisTpl;
-
添加key/value
redisTpl.opsForValue().set("name", "shadowolf");
-
獲取key/value
String value = redisTpl.opsForValue().get("name");