Login
网站首页 > 文章中心 > 其它

springboot整合redis 配置文件及配置类_一)_springboot整合redis哨兵配置

作者:小编 更新时间:2023-08-10 12:00:35 浏览量:8人看过

# Redis数据库索引(默认为0)
spring.redis.database=1
# Redis服务器地址
spring.redis.host=12⑦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 {
public RedisTemplate redisTemplate(LettuceConnectionFactory factory) {
    RedisTemplate template = new RedisTemplate();
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    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);
    return template;

}

    
        org.springframework.boot
        spring-boot-starter-cache
    
    
        org.springframework.boot
        spring-boot-starter-data-redis
    

以上就是土嘎嘎小编为大家整理的springboot整合redis 配置文件及配置类_一)相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章