栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

jedis连接redis哨兵

jedis连接redis哨兵

jedis连接redis哨兵
在有哨兵监控的主从结构下,使用jedis连接有以下几个步骤

    使用JedisSentinelPool对象连接sentinelsentinel会返回给客户端当前master的地址
    这个地址必须是客户端可以识别的(使用虚拟linux系统实验的情况下不能配置localhost或者127.0.0.1)

sentinel.conf

...
sentinel monitor mymaster 192.168.1.8 6379 2
...
    客户端会拿着这个地址去请求mater节点
		...
		String masterName = "mymaster";
        Set sentinels = new HashSet<>();
        sentinels.add("192.168.1.8:25001");
        sentinels.add("192.168.1.8:25001");
        sentinels.add("192.168.1.8:25001");
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();//默认的配置
        JedisSentinelPool pool = new JedisSentinelPool(masterName, sentinels,poolConfig);
        Jedis jedis = pool.getResource();//获取jedis对象
        pool.close();
        ...

打印日志信息如下

JedisSentinelPool - Trying to find master from available Sentinels...
JedisSentinelPool - Connecting to Sentinel 192.168.1.8:25001
JedisSentinelPool - Found Redis master at 192.168.1.8:6379
JedisSentinelPool - Redis master running at 192.168.1.8:6379, starting Sentinel listeners...
JedisSentinelPool - Created JedisSentinelPool to master at 192.168.1.8:6379
...
JedisSentinelPool - Shutting down listener on 192.168.1.8:25001
JedisSentinelPool - Unsubscribing from Sentinel at 192.168.1.8:25001
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/701995.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号