SpringBoot+redis配置及測(cè)試的方法

2.1學(xué)過(guò)redis的同學(xué)都知道這個(gè)東西有集群版也有單機(jī)版,無(wú)論哪個(gè)版本配置起來(lái)都很簡(jiǎn)單
2.1.1首先找到配置文件

2.1.2然后配置集群版,直接在配置文件內(nèi)編輯即可

2.1.3配置單機(jī)版

找到測(cè)試文件夾,自動(dòng)注入redis模板

4.1操作String
@Testpublic void testString(){//操作String類型的數(shù)據(jù)ValueOperations<String, String> valueStr = redisTemplate.opsForValue();//存儲(chǔ)一條數(shù)據(jù)valueStr.set('goodsProdu','長(zhǎng)安');//獲取一條數(shù)據(jù)并輸出String goodsName = valueStr.get('goodsProdu');System.out.println(goodsName);//存儲(chǔ)多條數(shù)據(jù)Map<String,String> map = new HashMap<>();map.put('goodsName','福特汽車');map.put('goodsPrice','88888');map.put('goodsId','88'); valueStr.multiSet(map);//獲取多條數(shù)據(jù)System.out.println('========================================');List<String>list = new ArrayList<>();list.add('goodsName');list.add('goodsPrice');list.add('goodsId');list.add('goodsProdu'); List<String> listKeys = valueStr.multiGet(list);for (String key : listKeys) {System.out.println(key);} }
效果
. ____ _ __ _ _ / / ___’_ __ _ _(_)_ __ __ _ ( ( )___ | ’_ | ’_| | ’_ / _` | / ___)| |_)| | | | | || (_| | ) ) ) ) ’ |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::(v2.0.3.RELEASE)2018-06-21 09:45:31.328 INFO 8848 --- [ main] io.lettuce.core.KqueueProvider : Starting without optional kqueue library長(zhǎng)安========================================福特汽車8888888長(zhǎng)安
4.2測(cè)試hash數(shù)據(jù)
@Testpublic void testHash(){//創(chuàng)建對(duì)象HashOperations<String, String, String> opsForHash = redisTemplate.opsForHash();//存儲(chǔ)一條數(shù)據(jù)opsForHash.put('orderInfo','orderId','11');//獲取一條數(shù)據(jù)String value = opsForHash.get('orderInfo', 'orderId');System.out.println(value); //存儲(chǔ)多條數(shù)據(jù)Map<String,String> map = new HashMap<>();map.put('createTime','2018-06-21');map.put('orderSn','888888');opsForHash.putAll('orderInfo',map);//獲取多條數(shù)據(jù)List<String> listKey = new ArrayList<>();listKey.add('createTime');listKey.add('orderSn');List<String> info = opsForHash.multiGet('orderInfo', listKey);for (String s : info) {System.out.println(s); } }
效果
. ____ _ __ _ _ / / ___’_ __ _ _(_)_ __ __ _ ( ( )___ | ’_ | ’_| | ’_ / _` | / ___)| |_)| | | | | || (_| | ) ) ) ) ’ |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::(v2.0.3.RELEASE)2018-06-21 09:48:26.020 INFO 3852 --- [ main] c.b.s.SpringbootRedisApplicationTests : Starting SpringbootRedisApplicationTests on sixfly with PID 3852 (started by Administrator in D:work_spacespringbootdemospringboot-redis)2018-06-21 09:48:26.030 INFO 3852 --- [ main] c.b.s.SpringbootRedisApplicationTests : No active profile set, falling back to default profiles: default2018-06-21 09:48:26.174 INFO 3852 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2f953efd: startup date [Thu Jun 21 09:48:26 CST 2018]; root of context hierarchy2018-06-21 09:48:28.398 INFO 3852 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!2018-06-21 09:48:32.182 INFO 3852 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 2018-06-21 09:48:35.054 INFO 3852 --- [ main] c.b.s.SpringbootRedisApplicationTests : Started SpringbootRedisApplicationTests in 11.637 seconds (JVM running for 19.635)2018-06-21 09:48:36.390 INFO 3852 --- [ main] io.lettuce.core.EpollProvider : Starting without optional epoll library2018-06-21 09:48:36.398 INFO 3852 --- [ main] io.lettuce.core.KqueueProvider : Starting without optional kqueue library112018-06-21888888
到此這篇關(guān)于SpringBoot+redis配置及測(cè)試的方法的文章就介紹到這了,更多相關(guān)SpringBoot redis配置測(cè)試內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. asp文件用什么軟件編輯2. PHP基礎(chǔ)之生成器4——比較生成器和迭代器對(duì)象3. CentOS郵箱服務(wù)器搭建系列——SMTP服務(wù)器的構(gòu)建( Postfix )4. Docker 啟動(dòng)Redis 并設(shè)置密碼的操作5. ASP新手必備的基礎(chǔ)知識(shí)6. Vue axios獲取token臨時(shí)令牌封裝案例7. vue+element開發(fā)一個(gè)谷歌插件的全過(guò)程8. Spring如何替換掉默認(rèn)common-logging.jar9. 利用CSS制作3D動(dòng)畫10. JAVA 實(shí)現(xiàn)延遲隊(duì)列的方法

網(wǎng)公網(wǎng)安備