今天這篇博客也是學習springboot做的學習筆記,關于springboot集成redis,分享給有需要的小伙伴們,視頻看的動力節點
動力節點王鶴老師講解的springboot教程,由淺入深,帶你體驗Spring Boot的極速開發程序,內容豐富,涵蓋了SpringBoot開發的方方面面,并且同步更新到Spring Boot 2.x系列的最新版本,
視頻鏈接:https://www.bilibili.com/video/BV1XQ4y1m7ex
redis能幫我們分散掉資料庫的壓力,有了它能更好的支持并發性能!
可以這樣理解redis位于資料庫和springboot框架之間,起到資料快取的作用,
在idea當中已經集成了redis的插件配置

?
?
創建完成后會得到idea的驅動以及工具介面,
之后就要在本地啟動redis服務,這個程序就好像類似啟動mysql服務,
我們可以到redis的官網下載,根據自己的系統選擇x64or x32
windows
https://github.com/tporadowski/redis/releases
Linux
https://redis.io/download
之后在本地需要開啟redis服務
?
使用Java進行鏈接,向redis當中快取資料
配置 - -application.yml
spring: redis: host: 127.0.0.1 port: 6379 jedis: pool: max-active: 8 max-wait: -1ms max-idle: 500 min-idle: 0 lettuce: shutdown-timeout: 0ms
測驗類
package com.example.demo; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.RedisTemplate; @SpringBootTest class DemoApplicationTests { @Autowired private RedisTemplate<String, String> redisTemplate; @Test void contextLoads() { redisTemplate.opsForValue().set("myKey3", "4564"); System.out.println(redisTemplate.opsForValue().get("myKey3")); } }
由于框架已經添加了redis 所以只需要將 redisTemplate 注入到Bean當中就可以呼叫介面對redis進行資料快取,
當頁面查詢資料時首先去快取當中查找資料, 如果沒有資料再向資料庫請求資源,因為redis的存盤型別,存取速度很快,能在一定程度上級訓資料庫的壓力,提升并發性能,加固網站的穩定性,
我們可以起執行緒池對介面進行并發測驗,查看是否符合邏輯,必要的加上鎖,
?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/447033.html
標籤:其他
下一篇:Python 可變物件的賦值
