国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Java > 正文

SpringBoot初步連接redis詳解

2024-07-13 10:15:03
字體:
來源:轉載
供稿:網友

在初次用springboot連接redis的時候查看官方文檔和一些博客會發現配置文件非常的多,這就導致了在學習的開始的時候是沒有體驗的,其實利用springboot連接redis的時候并不需要那么多的配置

首先開啟redis服務器

springboot連接redis,spring,boot,redis,springboot整合redis,springboot使用redis

然后在springboot里面添加配置文件:

# Redis數據庫索引(默認為0)spring.redis.database=0# Redis服務器地址spring.redis.host=localhost# Redis服務器連接端口spring.redis.port=6379# Redis服務器連接密碼(默認為空)spring.redis.password=# 連接池最大連接數(使用負值表示沒有限制)spring.redis.pool.max-active=8# 連接池最大阻塞等待時間(使用負值表示沒有限制)spring.redis.pool.max-wait=-1# 連接池中的最大空閑連接spring.redis.pool.max-idle=8# 連接池中的最小空閑連接spring.redis.pool.min-idle=0# 連接超時時間(毫秒)spring.redis.timeout=0

最后在springboot的pom.xml文件中添加依賴:

    <dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-data-redis</artifactId>    </dependency>

然后在springboot的項目中寫一個測試類:

@RunWith(SpringRunner.class)@SpringBootTestpublic class ShoppingApplicationTests {	@Autowired	  private StringRedisTemplate stringRedisTemplate;	@Test	  public void test() throws Exception {		List<String> list =new ArrayList<>();		list.add("a");		list.add("b");		list.add("v");		stringRedisTemplate.opsForValue().set("abc", "測試");		stringRedisTemplate.opsForList().leftPushAll("qq",list);		// 向redis存入List		stringRedisTemplate.opsForList().range("qwe",0,-1).forEach(value ->{			System.out.println(value);		}		);	}

然后在redis里面便可以看到了剛才的新建的

springboot連接redis,spring,boot,redis,springboot整合redis,springboot使用redis

然后這就是最簡單的springboot連接redis的方式了

總結

以上就是本文關于SpringBoot初步連接redis詳解的全部內容,希望對大家有所幫助。


注:相關教程知識閱讀請移步到JAVA教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 信丰县| 固阳县| 犍为县| 梓潼县| 牡丹江市| 凌源市| 吴江市| 湖南省| 沙河市| 清水河县| 南投市| 博兴县| 扎兰屯市| 环江| 阿拉善右旗| 清原| 靖安县| 翼城县| 玉屏| 栾川县| 农安县| 朝阳区| 石台县| 钦州市| 岳阳市| 锦屏县| 鱼台县| 慈利县| 五台县| 乌什县| 灵川县| 达拉特旗| 博乐市| 肥乡县| 南汇区| 柳州市| 侯马市| 青铜峡市| 衡东县| 天全县| 荥经县|