Springboot using the Redis database

Source: Internet
Author: User
Tags redis server

 (1) The Pom.xml file introduces the jar package as follows:

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

 (2) The Redis connection information is configured in the Application.properties file as follows:

# Redis Database index (default = 0) spring.redis.database=0# Redis server address spring.redis.host=172.31.19.222# Redis Server connection Port Spring.redis.port=6379# Redis Server connection password (default is empty) Spring.redis.password=# Connection pool Maximum number of connections (using negative values for No limit) Spring.redis.pool.max-active=8# Connection pool maximum blocking wait time (with negative values for No limit) Spring.redis.pool.max- Wait=-1# Maximum idle connection in connection pool Spring.redis.pool.max-idle=8# Minimum idle connection in connection pool spring.redis.pool.min-idle=0# Connection time-out (ms) Spring.redis.timeout=0

(3) Testing the Redis cache

 PackageSpringboot.web;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.data.redis.core.StringRedisTemplate;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RestController; @RestController Public classHellocontroller {@AutowiredPrivatestringredistemplate stringredistemplate; @RequestMapping ("/redishandler")     PublicString Redishandler () {Stringredistemplate.opsforvalue (). Set ("K5", "Springboot Redis"); returnStringredistemplate.opsforvalue (). Get ("K5"); }}

  (4) Start the project, call the Reidshandler method, query the Redis server information, as follows:

   

Springboot using the Redis database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.