redis 依赖_springboot|springboot集成redis缓存
生活随笔
收集整理的這篇文章主要介紹了
redis 依赖_springboot|springboot集成redis缓存
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
javaDEMO
本網站記錄了最全的各種JavaDEMO ,保證下載,復制就是可用的,包括基礎的, 集合的, spring的, Mybatis的等等各種,助力你從菜鳥到大牛,記得收藏哦~~https://www.javastudy.cloud
springboot集成redis
集面主要是以下幾步:
引入redis相關的依賴
配置redis的連接信息
在controller 里面測試redis
引入redis相關的依賴
在不考慮redis連接池的情況下,只配這個依賴就可以了,如使用redis連接池,還需額外引一個common-pools的
implementation 'org.springframework.boot:spring-boot-starter-data-redis'配置springboot連接信息
spring.redis.host=localhost#注意端口號, 上篇文章中, 我們主機的端口號是63379spring.redis.port=63379spring.redis.password=javastudycontroller中測試調用
/** * @Author https://www.javastudy.cloud * @CreateTime 2019/11/4 **/@RestControllerpublic class RedisController { @Autowired private StringRedisTemplate redisTemplate; /** * 在實際開發中, 對redis的操作通常會封裝一個RedisTools * RedisTools中還是使用StringRedisTemplate來對redis進行操作 * 雖然redis提供了很多數類型,更多的使用場景還是把value轉成json或者直接轉成字符串存redis中 * @return */ @RequestMapping("redis/testRedis") public String testRedis(){ //向redis里面設置key redisTemplate.opsForValue().set("study","javaDemo"); //從redis里面取出key-value String result = redisTemplate.opsForValue().get("study"); return result; }}輸出結果:
DEMO總評
在本DEMO中,演示了redis的存和取,但是沒有使用連接池,因此本DEMO也僅供學習和小并發使用,在高并發前,還是要使用redis連接池來管理連接,存取數據. 加油吧,少年!
DEMO下載
https://img.hacpai.com/file/2019/11/demospringbootredis-9333737a.zip
可添加小刀微信獲取源碼
往期熱文springboot|springboot連接mysql數據庫springboot|新建Controller和RestController接收請求springboot|Controller接收處理GET,POST請求入參docker|docker安裝mysql數據庫點在看的都沒有bug!!!總結
以上是生活随笔為你收集整理的redis 依赖_springboot|springboot集成redis缓存的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python导入标准库对象的语句_Pyt
- 下一篇: springboot 获取applica