Redis主从配置及HA方案(2)

$ redis-cli -p 26379 sentinel master mymaster//查看master的状态 SENTINEL slaves mymaster //查看salves的状态 SENTINEL sentinels mymaster //查看哨兵的状态 SENTINEL get-master-addr-by-name mymaster//获取当前master的地址 info sentinel//查看哨兵信息 

写个代码测试下:

public static void main(String[] args) { Set<String> sentinels = new HashSet<String>(); sentinels.add(new HostAndPort("172.30.21.96", 26379).toString()); sentinels.add(new HostAndPort("172.30.21.88", 26379).toString()); sentinels.add(new HostAndPort("172.30.21.89", 26379).toString()); sentinels.add(new HostAndPort("172.30.21.90", 26379).toString()); sentinels.add(new HostAndPort("172.30.21.91", 26379).toString()); JedisSentinelPool sentinelPool = new JedisSentinelPool("mymaster", sentinels); System.out.println("Current master: " + sentinelPool.getCurrentHostMaster().toString()); Jedis master = sentinelPool.getResource(); //master.set("username","jager"); System.out.println(master.get("username")); sentinelPool.close(); sentinelPool.destroy(); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/191cc75069b26c931a2b84cc2592cb87.html