Spring Boot Redis

Source: Internet
Author: User
Tags server port redis server

Dependency

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

Application-redis.properties

#########基础配置#########spring.redis.database=0#spring.redis.url=redis://user:[email protected]:6379spring.redis.host=spring.redis.port=spring.redis.password=spring.redis.timeout=30000spring.redis.ssl=false#########redis哨兵设置##########spring.redis.sentinel.master=#spring.redis.sentinel.nodes=#spring.redis.cluster.max-redirects=#spring.redis.cluster.nodes=#########jedis client 线程池配置##########spring.redis.jedis.pool.max-active=#spring.redis.jedis.pool.max-idle=#spring.redis.jedis.pool.min-idle=#spring.redis.jedis.pool.max-wait=#########lettuce client 线程池配置(默认)#########spring.redis.lettuce.pool.max-active=10spring.redis.lettuce.pool.max-idle=5spring.redis.lettuce.pool.min-idle=1spring.redis.lettuce.pool.max-wait=20000spring.redis.lettuce.shutdown-timeout=10

Test

@RunWith(SpringRunner.class)@SpringBootTestpublic class AnnotationAppContextTest {    @Autowired    private RedisTemplate<String,String> redisTemplate;    @Autowired    private StringRedisTemplate stringRedisTemplate;    @Test    public void setTest(){        redisTemplate.opsForValue().set("key1","val1", 100);        String key1 = redisTemplate.opsForValue().get("key1");        System.err.println("=============="+key1);    }}

SOURCE-redisproperties

@ConfigurationProperties(prefix = "spring.redis")public class RedisProperties {    /**     * Database index used by the connection factory.     */    private int database = 0;    /**     * Connection URL. Overrides host, port, and password. User is ignored. Example:     * redis://user:[email protected]:6379     */    private String url;    /**     * Redis server host.     */    private String host = "localhost";    /**     * Login password of the redis server.     */    private String password;    /**     * Redis server port.     */    private int port = 6379;    /**     * Whether to enable SSL support.     */    private boolean ssl;    /**     * Connection timeout.     */    private Duration timeout;    private Sentinel sentinel;    private Cluster cluster;    private final Jedis jedis = new Jedis();    private final Lettuce lettuce = new Lettuce();}   

SOURCE-redisautoconfiguration

 @Configuration @conditionalonclass (redisoperations.class) @EnableConfigurationProperties ( Redisproperties.class) @Import ({lettuceconnectionconfiguration.class, jedisconnectionconfiguration.class}) public Class Redisautoconfiguration {@Bean @ConditionalOnMissingBean (name = "Redistemplate") public Redistemplate<ob Ject, object> redistemplate (Redisconnectionfactory redisconnectionfactory) throws Unknownhostexception { Redistemplate<object, object> template = new redistemplate<> (); Template.setconnectionfactory (redisconnectionfactory); return template; } @Bean @ConditionalOnMissingBean (stringredistemplate.class) public stringredistemplate stringredistemplate ( Redisconnectionfactory redisconnectionfactory) throws unknownhostexception {stringredistemplate template = New Stringredistemplate (); Template.setconnectionfactory (redisconnectionfactory); return template; }}

Reference: 78123253?locationnum=6&fps=1

Spring Boot 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.