哨兵模式连接master方式

哨兵模式连接master方式,第1张

哨兵模式连接master方式

1工具连接
(1).首先

ENTINEL get-master-addr-by-name [mastername]

获取master ip port
(2)redis-cli -h ip -p 端口
例如:

redis-cli -h 10.233.50.21 -p 6379

2代码连接

@Configuration
public class RedisConfig {

    @Bean
    public RedisTemplate redisTemplate(LettuceConnectionFactory jedisConnectionFactory) {
        RedisSentinelConfiguration configuration=jedisConnectionFactory.getSentinelConfiguration();
        jedisConnectionFactory.setDatabase(configuration.getDatabase());
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(jedisConnectionFactory);
        // 设置value的序列化规则和 key的序列化规则
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());

        RedisSerializer stringSerializer = new StringRedisSerializer();
        RedisSerializer jackSerializer=new GenericJackson2JsonRedisSerializer();
        redisTemplate.setKeySerializer(stringSerializer);
        redisTemplate.setValueSerializer(jackSerializer);
        redisTemplate.setHashKeySerializer(stringSerializer);
        redisTemplate.setHashValueSerializer(jackSerializer);
        redisTemplate.afterPropertiesSet();
        System.out.println(redisTemplate);
        return redisTemplate;
    }

}

yaml配置

spring:
#中间省略
  redis: 
    sentinel:
      master: mymaster
      nodes: tstr501314.cn.wal-mart.com:26379
    database: 12
    password: foobared
    timeout: 20000
    jedis:
      pool:
        max-wait: 1000
        max-active: 100
        min-idle: 10
        max-idle: 50

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5717566.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存