redis读写分离 java_redis主从, java客户端使用jedis连接master,读请求会被路由到slave吗?...

主的配置好ip和端口,从的配置好Slaveof的master地址和端口号,哨兵监控master的ip和端口号,java代码直接master的name和密码就行了。

`

public static void main(String[] args) {

Set sentinels = new HashSet();

String hostAndPort1 = "127.0.0.1:26379";

String hostAndPort2 = "127.0.0.1:26380";

sentinels.add(hostAndPort1);

sentinels.add(hostAndPort2);

String clusterName = "mymaster";

String password = "123456";

JedisSentinelPool redisSentinelJedisPool = new JedisSentinelPool(clusterName,sentinels,password);

Jedis jedis = null;

try {

jedis = redisSentinelJedisPool.getResource();

System.out.println(jedis.get("key"));

} catch (Exception e) {

e.printStackTrace();

} finally {

redisSentinelJedisPool.returnBrokenResource(jedis);

}

redisSentinelJedisPool.close();

`

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页