Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does SpringBoot connect to redis

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to connect SpringBoot to redis". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First, start the redis server:

Then add the configuration file to the springboot:

# Redis database index (default is 0) spring.redis.database=0# Redis server address spring.redis.host=localhost# Redis server connection port spring.redis.port=6379# Redis server connection password (default is empty) maximum number of spring.redis.password=# connection pool connections (use negative values for no limit) maximum blocking wait time for spring.redis.pool.max-active=8# connection pool (use negative values for no limit) Maximum idle connections in spring.redis.pool.max-wait=-1# connection pool minimum idle connections in spring.redis.pool.max-idle=8# connection pool spring.redis.pool.min-idle=0# connection timeout (milliseconds) spring.redis.timeout=0

Finally, add the dependency to the pom.xml file of springboot:

Org.springframework.boot spring-boot-starter-data-redis

Then write a test class in springboot's project:

@ RunWith (SpringRunner.class) @ SpringBootTestpublic class ShoppingApplicationTests {@ Autowired private StringRedisTemplate stringRedisTemplate; @ Testpublic void test () throws Exception {List list = new ArrayList (); list.add ("a"); list.add ("b"); list.add ("v") StringRedisTemplate.opsForValue () .set ("abc", "test"); stringRedisTemplate.opsForList () .leftPushAll ("qq", list); / / deposit List stringRedisTemplate.opsForList () .range ("qwe", 0mam qwe 1) .forEach (value-> {System.out.println (value)) into redis });}

Then you can see the newly built one in redis.

And then this is the easiest way for springboot to connect to redis.

This is the end of "how to connect SpringBoot to redis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report