欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot初步連接redis詳解

 更新時(shí)間:2017年12月20日 10:05:36   作者:Somersames  
這篇文章主要介紹了SpringBoot初步連接redis詳解,具有一定借鑒價(jià)值,需要的朋友可以參考下。

在初次用springboot連接redis的時(shí)候查看官方文檔和一些博客會(huì)發(fā)現(xiàn)配置文件非常的多,這就導(dǎo)致了在學(xué)習(xí)的開(kāi)始的時(shí)候是沒(méi)有體驗(yàn)的,其實(shí)利用springboot連接redis的時(shí)候并不需要那么多的配置

首先開(kāi)啟redis服務(wù)器

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

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

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

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

然后在springboot的項(xiàng)目中寫(xiě)一個(gè)測(cè)試類(lèi):

@RunWith(SpringRunner.class)
@SpringBootTest
public 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", "測(cè)試");
		stringRedisTemplate.opsForList().leftPushAll("qq",list);
		// 向redis存入List
		stringRedisTemplate.opsForList().range("qwe",0,-1).forEach(value ->{
			System.out.println(value);
		}
		);
	}

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

然后這就是最簡(jiǎn)單的springboot連接redis的方式了

總結(jié)

以上就是本文關(guān)于SpringBoot初步連接redis詳解的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:

SpringBoot優(yōu)化技巧

Spring Boot 微服務(wù)項(xiàng)目的推薦部署方式

Springboot之于Spring的優(yōu)勢(shì)

如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!

相關(guān)文章

最新評(píng)論