哨兵模式java实例

 1 /**
 2  * 测试Redis哨兵模式
 3  * @author liu
 4  */
 5 public class TestSentinels {
 6     @SuppressWarnings("resource")
 7     @Test
 8     public void testSentinel() {
 9         JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
10         jedisPoolConfig.setMaxTotal(10);
11         jedisPoolConfig.setMaxIdle(5);
12         jedisPoolConfig.setMinIdle(5);
13         // 哨兵信息
14         Set<String> sentinels = new HashSet<>(Arrays.asList("192.168.11.128:26379",
15                 "192.168.11.129:26379","192.168.11.130:26379"));
16         // 创建连接池
17         JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels,jedisPoolConfig,"123456");
18         // 获取客户端
19         Jedis jedis = pool.getResource();
20         // 执行两个命令
21         jedis.set("mykey", "myvalue");
22         String value = jedis.get("mykey");
23         System.out.println(value);
24     }
25 }
原文地址:https://www.cnblogs.com/cowshed/p/11397707.html