美文网首页redis
redis sentinel 读写分离(四)

redis sentinel 读写分离(四)

作者: 8e7f75130086 | 来源:发表于2018-10-05 18:14 被阅读806次

    redis sentinel 读写分离(一)
    redis sentinel 读写分离(二)
    redis sentinel 读写分离(三)
    redis sentinel 读写分离(四)
    redis sentinel 读写分离(五)
    redis sentinel 读写分离(六)
    redis sentinel 读写分离(七)
    redis sentinel 读写分离(八)
    redis sentinel 读写分离(九)

    从sentinel中获取redis实例的相关信息,sentinel提供了相应的API

    JedisSentinelPool如何获取到redis master的信息

    在redis客户端执行命令get-master-addr-by-name mymaster即可获取redis master实例

    127.0.0.1:26379> sentinel get-master-addr-by-name mymaster
    1) "10.200.41.26"
    2) "15000"
    

    在JedisSentinelPool中,通过如下方法获取

    List<String> masterAddr = jedis.sentinelGetMasterAddrByName(masterName);
    

    JedisSentinelSlaveLB如何获取redis slave的信息

    在redis客户端执行命令sentinel slaves mastername即可获取所有slave redis实例

    127.0.0.1:26379> sentinel slaves mymaster
    1)  1) "name"
        2) "10.200.41.252:15000"
        3) "ip"
        4) "10.200.41.252"
        5) "port"
        6) "15000"
        7) "runid"
        8) "fb7254e2ebaf6463143da0853009f553c0c9fcbb"
        9) "flags"
       10) "slave"
       11) "pending-commands"
       12) "0"
       13) "last-ping-sent"
       14) "0"
       15) "last-ok-ping-reply"
       16) "193"
       17) "last-ping-reply"
       18) "193"
       19) "down-after-milliseconds"
       20) "10000"
       21) "info-refresh"
       22) "3441"
       23) "role-reported"
       24) "slave"
       25) "role-reported-time"
       26) "704168613"
       27) "master-link-down-time"
       28) "0"
       29) "master-link-status"
       30) "ok"
       31) "master-host"
       32) "10.200.41.26"
       33) "master-port"
       34) "15000"
       35) "slave-priority"
       36) "100"
       37) "slave-repl-offset"
       38) "1204615366"
    

    在JedisSentinelSlaveLB中,通过如下方法获取

    List<Map<String, String>> slavesAddrs = jedis.sentinelSlaves(masterName);
    

    sentinel事件消息格式

    /**
    * <p>Description: 一次master切换会经历如下事件流程</p>
    * <p>[22503] 09 Oct 16:28:41.462 # +sdown master mymaster 10.200.41.26 15000</p>
    * <p>[22503] 09 Oct 16:28:41.614 # +new-epoch 9214</p>
    * <p>[22503] 09 Oct 16:28:41.628 # +vote-for-leader f1d9bd7269fd18b5a1dbc10e333c70b0a18ff246 9214</p>
    * <p>[22503] 09 Oct 16:28:42.535 # +odown master mymaster 10.200.41.26 15000 #quorum 3/2</p>
    * <p>[22503] 09 Oct 16:28:43.929 # +switch-master mymaster 10.200.41.26 15000 10.200.41.252 15000</p>
    * <p>[22503] 09 Oct 16:28:43.930 * +slave slave 10.200.41.253:15000 10.200.41.253 15000 @ mymaster 10.200.41.252 15000</p>
    * <p>[22503] 09 Oct 16:28:43.950 * +slave slave 10.200.41.26:15000 10.200.41.26 15000 @ mymaster 10.200.41.252 15000</p>
    * <p>[22503] 09 Oct 16:28:53.971 # +sdown slave 10.200.41.26:15000 10.200.41.26 15000 @ mymaster 10.200.41.252 15000</p>      
    * <p>----------------------------------------------------------------------------------------------------------------------</p>
    * <p>Description: 原master恢复后经历如下事件</p>
    * <p>[22503] 09 Oct 16:35:03.461 # -sdown slave 10.200.41.26:15000 10.200.41.26 15000 @ mymaster 10.200.41.252 15000</p>
    * <p>[22503] 09 Oct 16:35:13.395 * +convert-to-slave slave 10.200.41.26:15000 10.200.41.26 15000 @ mymaster 10.200.41.252 15000</p>
    * <p>----------------------------------------------------------------------------------------------------------------------</p>
    * <p>Description: slave宕机后经历如下事件</p>
    * <p>[22503] 09 Oct 16:37:45.244 # +sdown slave 10.200.41.26:15000 10.200.41.26 15000 @ mymaster 10.200.41.252 15000</p>
    * <p>----------------------------------------------------------------------------------------------------------------------</p>
    * <p>Description: slave宕机恢复后经历如下事件</p>
    * <p>[22503] 09 Oct 16:38:56.837 * +reboot slave 10.200.41.26:15000 10.200.41.26 15000 @ mymaster 10.200.41.252 15000</p>
    * <p>[22503] 09 Oct 16:38:56.894 # -sdown slave 10.200.41.26:15000 10.200.41.26 15000 @ mymaster 10.200.41.252 15000</p>
    * <p>----------------------------------------------------------------------------------------------------------------------</p>
    **/
    

    相关文章

      网友评论

        本文标题:redis sentinel 读写分离(四)

        本文链接:https://www.haomeiwen.com/subject/naeqaftx.html