zoukankan      html  css  js  c++  java
  • 架构师养成记--33.Redis哨兵、redis简单事务

    Redis哨兵

      有了主从复制,如果我想想对主从服务器进行监控,在redis2.6后提供了哨兵机制,2.6有哨兵1.0版本,并不稳定。2.8以后的哨兵功能才稳定起来。

      顾名思义,哨兵就是监控Redis系统的运行状况,其主要功能有两点:

    1. 监控主数据库和从数据库是否正常运行
    2. 主数据库出现故障时,可以自动将从数据转换为主数据,实现自动切换

    实现步骤:

    1. 在其中一台从服务器配置sentinel.conf
    2. copy文件sentinel.conf文件到/usr/local/redis/etc/中
    3. 修改sentinel.conf文件
          sentinel monitor mymaster 192.168.1.17 6379 1 #名称 ip 端口 选票次数
          sentinel down-after-milliseconds mymaster 5000 #默认1s检测一次,这里配置超时5000毫秒
          sentinel failover-timeout mymater 800000
          sentinel parallel-syncs mymaster 2
          sentinel can-failover mymaster yes
    4. 启动sentinel哨兵 :/usr/local/redis/bin/redis-server /usr/local/redis/etc/sentinel.conf --sentinel &
    5. 查看哨兵相关信息命令
          /usr/local/redis/bin/redis-cli -h 192.168.17 -p 26379 info sentinel
    6. 关闭主服务器查看集群信息
          /usr/local/redis/bin/redis-cli -h 192.168.1.17 -p 6379 shutdown

    Redis简单事务

      redis的事务非常简单,首先是要multi方法打开事务,然后set,这时set的数据都会放入队列里进行保存,最后是要exec执行,把数据依次存储到redis中,使用discard方法取消事务。

      redis的事务不能保证同事成功或失败进行提交或回滚,所以redis事务的实现目前还是比较简单的,如下图,虽然在incr name的时候报错了,但是incr age还是成功了的。

  • 相关阅读:
    codeforces C. Fixing Typos 解题报告
    codeforces B. The Fibonacci Segment 解题报告
    codeforces B. Color the Fence 解题报告
    codeforces B. Petya and Staircases 解题报告
    codeforces A. Sereja and Bottles 解题报告
    codeforces B. Levko and Permutation 解题报告
    codeforces B.Fence 解题报告
    tmp
    API 设计 POSIX File API
    分布式跟踪的一个流行标准是OpenTracing API,该标准的一个流行实现是Jaeger项目。
  • 原文地址:https://www.cnblogs.com/sigm/p/6507545.html
Copyright © 2011-2022 走看看