网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

springbootredis

dependency

成都创新互联公司-专业网站定制、快速模板网站建设、高性价比博乐网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式博乐网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖博乐地区。费用合理售后完善,十余年实体公司更值得信赖。

        
            org.springframework.boot
            spring-boot-starter-data-redis
        
        
            org.apache.commons
            commons-pool2
        

application-redis.properties

#########基础配置#########
spring.redis.database=0
#spring.redis.url=redis://user:password@example.com:6379
spring.redis.host=
spring.redis.port=
spring.redis.password=
spring.redis.timeout=30000
spring.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=10
spring.redis.lettuce.pool.max-idle=5
spring.redis.lettuce.pool.min-idle=1
spring.redis.lettuce.pool.max-wait=20000
spring.redis.lettuce.shutdown-timeout=10

Test

@RunWith(SpringRunner.class)
@SpringBootTest
public class AnnotationAppContextTest {
    @Autowired
    private RedisTemplate 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);
    }
}

源码-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:password@example.com: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();
}   

源码-RedisAutoConfiguration

@Configuration
@ConditionalOnClass(RedisOperations.class)
@EnableConfigurationProperties(RedisProperties.class)
@Import({ LettuceConnectionConfiguration.class, JedisConnectionConfiguration.class })
public class RedisAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(name = "redisTemplate")
    public RedisTemplate redisTemplate(
            RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {
        RedisTemplate 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;
    }

}

参考:https://blog.csdn.net/abombhz/article/details/78123253?locationNum=6&fps=1


网页题目:springbootredis
文章源于:http://bjjierui.cn/article/psocgg.html

其他资讯