zoukankan      html  css  js  c++  java
  • springboot整合redis 配置文件及配置类(一)

    # Redis数据库索引(默认为0)
    spring.redis.database=1
    # Redis服务器地址
    spring.redis.host=127.0.0.1
    # Redis服务器连接端口
    spring.redis.port=6379
    # Redis服务器连接密码(默认为空)
    spring.redis.password=
    # 连接池最大连接数(使用负值表示没有限制)
    spring.redis.pool.max-active=200
    # 连接池最大阻塞等待时间(使用负值表示没有限制)
    spring.redis.pool.max-wait=-1
    # 连接池中的最大空闲连接
    spring.redis.pool.max-idle=10
    # 连接池中的最小空闲连接
    spring.redis.pool.min-idle=0
    # 连接超时时间(毫秒)
    spring.redis.timeout=1000
    
    /**
     * redis配置类
     * @author Administrator
     *
     */
    @Configuration
    public class RedisConfig {
        
        @Bean
        public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory factory) {
            
            RedisTemplate<String, Object> template = new RedisTemplate();
            template.setConnectionFactory(factory);
            Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
            ObjectMapper om = new ObjectMapper();
            om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
            om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
            jackson2JsonRedisSerializer.setObjectMapper(om);
            StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
            // key采用String的序列化方式
            template.setKeySerializer(stringRedisSerializer);
            // hash的key也采用String的序列化方式
            template.setHashKeySerializer(stringRedisSerializer);
            // value序列化方式采用jackson
            template.setValueSerializer(jackson2JsonRedisSerializer);
            // hash的value序列化方式采用jackson
            template.setHashValueSerializer(jackson2JsonRedisSerializer);
            template.afterPropertiesSet();
            return template;
        }
        
    }
    <!-- redis所需要的依赖 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-cache</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>
  • 相关阅读:
    Bonding
    负载均衡
    XML
    wireshark
    IE
    轨迹系列7——Socket总结及实现基于TCP或UDP的809协议方法
    轨迹系列6——车载GPS对接方案汇总小结(809、自定义协议、前置库、WS)
    基于R树索引的点面关系判断以及效率优化统计
    WebGIS中以version方式实现代码更新后前端自动读取更新代码的方法
    轨迹系列5——验证轨迹GPS坐标转换为本地坐标的四/七参数是否准确的一种方案
  • 原文地址:https://www.cnblogs.com/ch94/p/14741343.html
Copyright © 2011-2022 走看看