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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)