Springboot Integrated Redis

Source: Internet
Author: User
Tags redis server

These days just the new project used Redis, search the Internet, summed up

There are two kinds of online, one is to use the class to configure the management Redis, and the other is to write in Yaml or properties

I feel the way to unload Yaml is more intuitive, simple, below to briefly introduce, quite simple

1. Our project uses springboot2.0, and then we introduce redis dependencies into the POM in the following format

        < Dependency >            < groupId >org.springframework.boot</groupId>            <  Artifactid>spring-boot-starter-data-redis</artifactid>         </dependency>

2. Inject in your class

    @Autowired    private Stringredistemplate stringredistemplate;

Or

    @Autowired    private Redistemplate redistemplate;

Then save the key, take the key, set the timeout time, and so on, other types of use Baidu on the line, a lot.

Use: Redistemplate.opsforvalue (). Set ("Name", "Tom"); Result: Redistemplate.opsforvalue (). Get ("name")  output is Tom

Oh, yes, add a basic configuration file to the properties

# Redis Database index (default is 0) spring.redis.database=0# Redis server address spring.redis.host=127.0.0.1# 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 means there is 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 connections in the 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=5000

And then there's the search for all the approximate keys.

Stringredistemplate.keys ("xxx")

This usage must not be used in a production environment unless the amount of data is small ...

Springboot Integrated Redis

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.