Springboot整合Redis最簡單例子分享
1. 編寫目的
最簡單的例子,Springboot整合Redis。
2. 詳細過程
pom 文件添加依賴
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
配置redis
編輯application.yml文件。
spring:redis:port: 6379host: 39.106.198.74### 如果有密碼需要添加password
編寫一個controller類
package cn.smileyan.shirodemo.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.StringRedisTemplate;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class RedisController { @Autowired private StringRedisTemplate stringRedisTemplate; @RequestMapping('/') private String hello() { stringRedisTemplate.opsForValue().set('hello','world'); return 'SUCCESS'; }}
測試
運行項目,然后用瀏覽器打開localhost:8080/這個地址。
看到瀏覽器輸出SUCCESS后,使用Redis Desktop查看是否set成功。
3. 總結
非常簡單的例子,但還是記錄一下,在這個基礎上可以做很多事情,但是對于剛剛接觸的人來說,可能還是有用的。
以上這篇Springboot整合Redis最簡單例子分享就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. JavaWeb Servlet中url-pattern的使用2. jsp中sitemesh修改tagRule技術分享3. asp(vbscript)中自定義函數(shù)的默認參數(shù)實現(xiàn)代碼4. React優(yōu)雅的封裝SvgIcon組件示例5. 輕松學習XML教程6. php網(wǎng)絡安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究7. ASP刪除img標簽的style屬性只保留src的正則函數(shù)8. JSP servlet實現(xiàn)文件上傳下載和刪除9. ASP基礎知識VBScript基本元素講解10. 詳解瀏覽器的緩存機制
