摘要:經(jīng)過(guò)上述兩步的操作,你可以訪問(wèn)數(shù)據(jù)了。數(shù)據(jù)訪問(wèn)層通過(guò)來(lái)訪問(wèn)分鐘過(guò)期單元測(cè)試啟動(dòng)單元測(cè)試,你發(fā)現(xiàn)控制臺(tái)打印了單元測(cè)試通過(guò)源碼下載參考資料
這篇文章主要介紹springboot整合redis
引入依賴在pom文件中添加redis依賴:
配置數(shù)據(jù)源org.springframework.boot spring-boot-starter-data-redis
spring.redis.host=localhost spring.redis.port=6379 spring.redis.password= spring.redis.database=1 spring.redis.pool.max-active=8 spring.redis.pool.max-wait=-1 spring.redis.pool.max-idle=500 spring.redis.pool.min-idle=0 spring.redis.timeout=0
如果你的redis有密碼,配置下即可。經(jīng)過(guò)上述兩步的操作,你可以訪問(wèn)redis數(shù)據(jù)了。
數(shù)據(jù)訪問(wèn)層dao通過(guò)redisTemplate來(lái)訪問(wèn)redis:
@Repository public class RedisDao { @Autowired private StringRedisTemplate template; public void setKey(String key,String value){ ValueOperations單元測(cè)試ops = template.opsForValue(); ops.set(key,value,1, TimeUnit.MINUTES);//1分鐘過(guò)期 } public String getValue(String key){ ValueOperations ops = this.template.opsForValue(); return ops.get(key); } }
@RunWith(SpringRunner.class) @SpringBootTest public class SpringbootRedisApplicationTests { public static Logger logger= LoggerFactory.getLogger(SpringbootRedisApplicationTests.class); @Test public void contextLoads() { } @Autowired RedisDao redisDao; @Test public void testRedis(){ redisDao.setKey("name","forezp"); redisDao.setKey("age","11"); logger.info(redisDao.getValue("name")); logger.info(redisDao.getValue("age")); } }
啟動(dòng)單元測(cè)試,你發(fā)現(xiàn)控制臺(tái)打印了:
forezp
單元測(cè)試通過(guò);
源碼下載:https://github.com/forezp/Spr...
參考資料messaging-redis
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/70374.html
摘要:相比它支持存儲(chǔ)的類(lèi)型相對(duì)更多字符哈希集合有序集合列表,同時(shí)是線程安全的。基于的連接實(shí)例,可以在多個(gè)線程間并發(fā)訪問(wèn),且線程安全,滿足多線程環(huán)境下的并發(fā)訪問(wèn),同時(shí)它是可伸縮的設(shè)計(jì),一個(gè)連接實(shí)例不夠的情況也可以按需增加連接實(shí)例。 SpringBoot 是為了簡(jiǎn)化 Spring 應(yīng)用的創(chuàng)建、運(yùn)行、調(diào)試、部署等一系列問(wèn)題而誕生的產(chǎn)物,自動(dòng)裝配的特性讓我們可以更好的關(guān)注業(yè)務(wù)本身而不是外部的XML...
這篇文篇主要簡(jiǎn)述如何在springboot中驗(yàn)證表單信息。在springmvc工程中,需要檢查表單信息,表單信息驗(yàn)證主要通過(guò)注解的形式。 構(gòu)建工程 創(chuàng)建一個(gè)springboot工程,由于用到了 web 、thymeleaf、validator、el,引入相應(yīng)的起步依賴和依賴,代碼清單如下: org.springframework.boot ...
閱讀 3828·2021-11-24 09:39
閱讀 3024·2021-11-16 11:49
閱讀 2142·2019-08-30 13:54
閱讀 1172·2019-08-30 13:03
閱讀 1147·2019-08-30 11:10
閱讀 787·2019-08-29 17:10
閱讀 1309·2019-08-29 15:04
閱讀 1274·2019-08-29 13:02