$ 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(); }