java连接redis哨兵_Redis 哨兵模式Java 操作

1 //1.设置sentinel 各个节点集合

2 Set sentinelSet = new HashSet<>();3 sentinelSet.add("192.168.14.101:26379");4 sentinelSet.add("192.168.14.102:26380");5 sentinelSet.add("192.168.14.103:26381");6

7 //2.设置jedispool 连接池配置文件

8 JedisPoolConfig config = newJedisPoolConfig();9 config.setMaxTotal(10);10 config.setMaxWaitMillis(1000);11

12 //3.设置mastername,sentinelNode集合,配置文件,Redis登录密码

13 JedisSentinelPool jedisSentinelPool = new JedisSentinelPool("mymaster",sentinelSet,config,"123");14 Jedis jedis = null;15 try{16 jedis =jedisSentinelPool.getResource();17 //获取Redis中key=hello的值

18 String value = jedis.get("hello");19 System.out.println(value);20 } catch(Exception e) {21 e.printStackTrace();22 } finally{23 if(jedis != null){24 jedis.close();25 }26 }

你可能感兴趣的:(java连接redis哨兵)