当前位置:

首页 > 编程开发 > Redis之sentinel哨兵集群怎么部署

Redis之sentinel哨兵集群怎么部署

Redis Assistant
Redis Assistant

Redis Assistant 是一款为Redis设计的高效可视化管理与监控工具,提供多种操作模式,高效处理服务器数据。日常使用里的持续防护和信息管理会更突出,适合把安全控制放进长期使用流程中的场景。

立即下载
¥19
Windows/macOS/Linux 2026-08-22
正版软件 Windows macOS软件 Linux 数据库管理工具

一、Redissentinel哨兵集群概述(1)Redis哨兵概述*Sentinel哨兵:这是一个分布式系统,该进程是用于监控Redis集群中Master主服务器的工作状态,在Master主服务器发生故障时,可以实现Master和Slave服务器的秒级切换,保证系统有一个Master主服务器,提供了Redis集群的高可用,在Reids2.6.版本时被加入,到2.8版本之后得到了稳定Redis哨兵和Redis主从的区别:Redis哨兵:主服务器出现故障后,会有一个从服务器代替主服务器Redis主从:主服务器

本文目录

    一、Redis sentinel哨兵集群概述

    (1)Redis哨兵概述

    *Sentinel 哨兵:这是一个分布式系统,该进程是用于监控Redis集群中Master主服务器的工作状态,在Master主服务器发生故障时,可以实现Master和Slave服务器的秒级切换,保证系统有一个Master主服务器,提供了Redis集群的高可用,在Reids2.6.版本时被加入,到2.8版本之后得到了稳定

    Redis哨兵和Redis主从的区别:

    Redis哨兵:主服务器出现故障后,会有一个从服务器代替主服务器

    Redis主从:主服务器出现故障后,从服务器不会做任何事

    Redis之sentinel哨兵集群怎么部署

    (2)Redis哨兵的工作机制

    哨兵只需要部署在master主服务器上即可

    工作进程:

    监控(Monitoring):哨兵通过流言协议(gossip protocols)会不断检查集群中每一台服务器是否运作正常

    提醒(Notification):当哨兵监控的某个redis服务器出现问题时,哨兵可以通过API(应用程序接口)向管理员或者其他应用程序发送通知

    自动故障转移(Automatic failover):在集群中如果有一个Master主服务器出现故障时,哨兵会通过投票协议(Agreement Protocols)开始一次自动故障迁移操作,他会选择一台数据较完整的Slave从服务器升级为主服务器,当客户端试图连接失效的Master主服务器时,集群也会向客户端返回新的Master主服务器的地址,使得集群可以使用现在的Master替换掉失效的Master。

    Master和Slave切换后,Master的redis主配置文件、Slave的redis主配置文件和哨兵的配置文件的内容都会发生相应的改变,即原来的Master的redis主配置文件会多一行Slave服务器的配置,之后哨兵的监控目标就会改变到现在的Master主服务器上

    Redis之sentinel哨兵集群怎么部署

    (3)哨兵的三个定时监控任务

    每隔10秒,每个Sentinel节点会向主节点和从节点发送info命令获取Redis数据节点的信息

    作用:

    通过向主节点执行info命令,获取从节点的信息,这也是为什么Sentinel节点不需要显式配置监控从节点。当有新的从节点加入时都可以立刻感知出来,当节点不可达或者故障转移后,可以通过info命令实时更新节点拓扑信息。

    每隔1秒,每个Sentinel节点会向主节点、从节点、发送一条ping命令做一次心跳检测,来确认这些节点当前是否可达如果主节点挂掉,那么sentinel,就会从剩余的从节点选择一个数据比较完整来做主节点

    二、部署Redis哨兵系统

    (1)实验环境

    系统ip主机名Redis版本端口扮演角色
    Centos7.4192.168.100.202masterRedis-5.0.4Redis:6379 Sentinel:26379Master
    Centos7.4192.168.100.203slave1Redis-5.0.4Redis:6379Slave
    Centos7.4192.168.100.204slave2Redis-5.0.4Redis:6379Slave

    (2)实验步骤 -在每台服务器上都安装Redis

    安装步骤相同,主机名、ip不同,下面只写Master配置

    [root@Centos7 ~]# hostnamectl set-hostname master
    [root@Centos7 ~]# su
    [root@master ~]# systemctl stop firewalld
    [root@master ~]# setenforce 0
    setenforce: SELinux is disabled
    [root@master ~]# mount /dev/cdrom /mnt/
    mount: /dev/sr0 写保护,将以只读方式挂载
    mount: /dev/sr0 已经挂载或 /mnt 忙
           /dev/sr0 已经挂载到 /mnt 上
    [root@master ~]# ll
    总用量 1928
    -rw-------. 1 root root    1264 1月  12 18:27 anaconda-ks.cfg
    -rw-r--r--  1 root root 1966337 6月   9 01:16 redis-5.0.4.tar.gz
    [root@master ~]# tar xf redis-5.0.4.tar.gz
    [root@master ~]# cd redis-5.0.4
    [root@master redis-5.0.4]# make
    [root@master redis-5.0.4]# mkdir -p /usr/local/redis
    [root@master redis-5.0.4]# cp /root/redis-5.0.4/src/redis-server /usr/local/redis/
    [root@master redis-5.0.4]# cp /root/redis-5.0.4/src/redis-cli /usr/local/redis/
    [root@master redis-5.0.4]# cp /root/redis-5.0.4/redis.conf  /usr/local/redis/ 
    [root@master redis-5.0.4]# vim /usr/local/redis/redis.conf   #修改
    。。。。。。
      68 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      69 bind 192.168.100.202  #修改为本机地址,如果为127.0.0.1就只能本机访问
      70 
    。。。。。。
      87 # are explicitly listed using the "bind" directive.
      88 protected-mode no  #关闭redis的保护模式,如果为yes的话其他客户端就无法连接到此服务器
      89 
    。。。。。。
     135 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
     136 daemonize yes  #开启redis的后台守护程序,即在redis开启之后是放在后台运行的
     137 
    。。。。。。
     262 # Note that you must specify a directory here, not a file name.
     263 dir /usr/local/redis/rdb
     264 
    。。。。。。
     506 #
     507 requirepass 123123  #去掉注释,修改redis的密码为123123
     508 
    #保存退出
    [root@slave2 redis-5.0.4]# mkdir /usr/local/redis/rdb
    [root@master redis-5.0.4]# vim /etc/init.d/redis
    #!/bin/sh
    # chkconfig: 2345 80 90
    # description: Start and Stop redis
    #PATH=/usr/local/bin:/sbin:/usr/bin:/bin
    REDISPORT=6379
    EXEC=/usr/local/redis/redis-server
    REDIS_CLI=/usr/local/redis/redis-cli
    PIDFILE=/var/run/redis_6379.pid
    CONF="/usr/local/redis/redis.conf"
    AUTH="123123"
    LISTEN_IP=$(netstat -utpln |grep redis-server |awk '{print $4}'|awk -F':' '{print $1}')
    
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                    echo "$PIDFILE exists, process is already running or crashed"
            else
                    echo "Starting Redis server..."
                    $EXEC $CONF
            fi
            if [ "$?"="0" ]
            then
                  echo "Redis is running..."
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                    echo "$PIDFILE does not exist, process is not running"
            else
                    PID=$(cat $PIDFILE)
                    echo "Stopping ..."
                    $REDIS_CLI -h $LISTEN_IP -p $REDISPORT -a $AUTH SHUTDOWN
                    while [ -x ${PIDFILE} ]
                   do
                        echo "Waiting for Redis to shutdown ..."
                        sleep 1
                    done
                    echo "Redis stopped"
            fi
            ;;
       restart|force-reload)
            ${0} stop
            ${0} start
            ;;
      *)
        echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
            exit 1
    esac
    [root@master redis-5.0.4]# chkconfig --add redis
    [root@master redis-5.0.4]# chmod 755 /etc/init.d/redis
    [root@master redis-5.0.4]# ln -s /usr/local/redis/* /usr/local/bin/
    [root@master redis-5.0.4]# /etc/init.d/redis start 
    Starting Redis server...
    5233:C 09 Jun 2021 01:25:53.069 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    5233:C 09 Jun 2021 01:25:53.069 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=5233, just started
    5233:C 09 Jun 2021 01:25:53.069 # Configuration loaded
    Redis is running...
    [root@master redis-5.0.4]# netstat -anpt | grep 6379
    tcp        0      0 192.168.100.202:6379    0.0.0.0:*               LISTEN      5234/redis-server 1

    -做redis主从

    ******(1)Master配置
    [root@master redis-5.0.4]# vim /usr/local/redis/redis.conf #修改
    。。。。。。
     292 #
     293  masterauth 123123  #配置主服务器密码,哨兵有一个问题,就是当主服务器坏掉,切换到从服务器时,原来的主服务器可以正常运行之后,再次加入集群是加不进去的,因为哨兵没有配置主服务器的密码,所以无法连接,所以在使用哨兵集群时,要把每台的主服务器密码都配置上,每台redis的密码最好都一样
     294 
    。。。。。。
     456 #
     457  min-replicas-to-write 1 #设置slave服务器的数量,当slave服务器少于这个数量时,Master主服务器会停止接收客户端的一切写请求
     458  min-replicas-max-lag 10 #设置主服务器和从服务器之间同步数据的超时时间,当超过此时间时,master主服务器会停止客户端的一切写操作,单位为秒
     459 #
    。。。。。。
    [root@master redis-5.0.4]# /etc/init.d/redis restart   #重启redis
    Stopping ...
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    Redis stopped
    Starting Redis server...
    5291:C 09 Jun 2021 02:04:39.132 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    5291:C 09 Jun 2021 02:04:39.132 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=5291, just started
    5291:C 09 Jun 2021 02:04:39.132 # Configuration loaded
    Redis is running...
    
    ******(2)Slave1配置
    [root@slave1 redis-5.0.4]# vim /usr/local/redis/redis.conf 
    。。。。。。
     285 #
     286 replicaof 192.168.100.202 6379  #在从服务器上指定主服务器的ip和端口
     287 
    。。。。。。
     292 #
     293 masterauth 123123  #指定主服务器上redis的密码
     294
    。。。。。。
    #保存退出
    [root@slave redis-5.0.4]# /etc/init.d/redis restart  #重启服务
    Stopping ...
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    Redis stopped
    Starting Redis server...
    5304:C 09 Jun 2021 02:11:32.241 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    5304:C 09 Jun 2021 02:11:32.241 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=5304, just started
    5304:C 09 Jun 2021 02:11:32.241 # Configuration loaded
    Redis is running...
    
    ******(3)Slave2配置
    [root@slave2 redis-5.0.4]# vim /usr/local/redis/redis.conf 
    。。。。。。
     286  replicaof 192.168.100.204 6379
     287 
     288 # If the master is password protected (using the "requirepass" configuration
     289 # directive below) it is possible to tell the replica to authenticate before
     290 # starting the replication synchronization process, otherwise the master will
     291 # refuse the replica request.
     292 #
     293  masterauth 123123
     294 
    。。。。。。
    #保存退出
    [root@slave2 redis-5.0.4]# /etc/init.d/redis restart 
    Stopping ...
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    Redis stopped
    Starting Redis server...
    5253:C 09 Jun 2021 17:50:25.680 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    5253:C 09 Jun 2021 17:50:25.680 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=5253, just started
    5253:C 09 Jun 2021 17:50:25.680 # Configuration loaded
    Redis is running...
    
    ******(3)验证主从是否成功
    [root@master ~]# redis-cli -h 192.168.100.202 -a 123123
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    192.168.100.202:6379> set aaa bbb
    OK
    192.168.100.202:6379> set bbb ccc 
    OK
    192.168.100.202:6379> keys *
    1) "aaa"
    2) "bbb"
    
    [root@slave1 ~]# redis-cli -h 192.168.100.203 -a 123123
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    192.168.100.203:6379> keys *
    1) "bbb"
    2) "aaa"
    192.168.100.203:6379> set ttt fff
    (error) READONLY You can't write against a read only replica.  #从服务器无法写入数据
    
    [root@slave2 redis-5.0.4]# redis-cli -h 192.168.100.204 -a 123123
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    192.168.100.204:6379> keys *
    1) "aaa"
    2) "bbb"
    192.168.100.204:6379> set ggg aaa
    (error) READONLY You can't write against a read only replica.
    
    #主从配置完成

    -配置哨兵

    ******(1)在master上配置sentinel哨兵
    [root@master ~]# cp redis-5.0.4/src/redis-sentinel /usr/local/redis/  #复制哨兵启动脚本
    [root@master ~]# cp redis-5.0.4/sentinel.conf /usr/local/redis/  #复制哨兵配置文件
    [root@master ~]# mkdir -p /var/redis/data  #创建日志文件存放位置	
    [root@master ~]# vim /usr/local/redis/sentinel.conf   #修改哨兵配置文件
    。。。。。。
     21 port 26379  #指定端口默认为26379
     22 
     23 # By default Redis Sentinel does not run as a daemon. Use 'yes' if you need it.
     24 # Note that Redis will write a pid file in /var/run/redis-sentinel.pid when
     25 # daemonized.
     26 daemonize yes  #yes为放在后台运行,使用no放在前台运行可以看到主从切换时候的信息
     27 
    。。。。。。
     64 # unmounting filesystems.
     65 dir /var/redis/data  #指定日志存放位置,就是刚才创建的路径
     66 
    。。。。。。
     83 # The valid charset is A-z 0-9 and the three characters ".-_".
     84 sentinel monitor mymaster 192.168.100.202  6379 1  #指定用户为mymaster,ip为202,端口为6379,1表示当有一台master出现故障时,就进行切换
     85 
     86 # sentinel a
    。。。。。。
    112 # Default is 30 seconds.
    113 sentinel down-after-milliseconds mymaster 3000  #指定master的失效时间,单位为毫秒3000为3秒,表示master超过3秒没响应就判定为故障
    114 
    。。。。。。
    145 # Default is 3 minutes.
    146 sentinel failover-timeout mymaster 180000  #切换操作完成的超时时间,单位为毫秒180000为180秒,在主从切换超过这个时间就判定为切换失败
    147 
    148 # SCRIPTS EXE
    。。。。。。
    102 #
    103  sentinel auth-pass mymaster 123123  #连接master和slave的密码
    104 sentinel config-epoch mymaster  1  #切换后最多有多少节点可以于新的master进行同步数据
    105 
    #保存退出
    [root@master ~]# /usr/local/redis/redis-sentinel /usr/local/redis/sentinel.conf  #启动哨兵
    1118:X 09 Jun 2021 18:09:29.027 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    1118:X 09 Jun 2021 18:09:29.027 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=1118, just started
    1118:X 09 Jun 2021 18:09:29.027 # Configuration loaded
    [root@master ~]# netstat -anpt | grep 26379
    tcp        0      0 0.0.0.0:26379           0.0.0.0:*               LISTEN      1119/redis-sentinel 
    tcp6       0      0 :::26379                :::*                    LISTEN      1119/redis-sentinel 
    [root@master ~]# kill -9 1119  #先关闭哨兵
    [root@master ~]# netstat -anpt | grep 26379
    [root@master ~]# sed -i '26s/yes/no/g' /usr/local/redis/sentinel.conf  #修改为前台启动
    [root@master ~]# /usr/local/redis/redis-sentinel /usr/local/redis/sentinel.conf  #再次开启哨兵,稍等一段时间会有提示
    1129:X 09 Jun 2021 18:11:02.585 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    1129:X 09 Jun 2021 18:11:02.585 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=1129, just started
    1129:X 09 Jun 2021 18:11:02.585 # Configuration loaded
    1129:X 09 Jun 2021 18:11:02.586 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 5.0.4 (00000000/0) 64 bit
      .-`` .-".  "\/    _.,_ ''-._                                   
     (    '      ,       .-`  | `,    )     Running in sentinel mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379
     |    `-._   `._    /     _.-'    |     PID: 1129
      `-._    `-._  `-./  _.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                                               
    
    1129:X 09 Jun 2021 18:11:02.586 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    1129:X 09 Jun 2021 18:11:02.586 # Sentinel ID is fce7776020cf12792fd239f6f9d34f2d3fdef98c
    1129:X 09 Jun 2021 18:11:02.586 # +monitor master mymaster 192.168.100.202 6379 quorum 1
    1129:X 09 Jun 2021 18:18:04.434 * +reboot slave 192.168.100.204:6379 192.168.100.204 6379 @ mymaster 192.168.100.202 6379  #看到新增两条消息,从服务器增加了203和204主服务器时202
    1129:X 09 Jun 2021 18:18:14.478 * +reboot slave 192.168.100.203:6379 192.168.100.203 6379 @ mymaster 192.168.100.202 6379
    
    #哨兵配置完成

    -测试哨兵的故障切换

    ******(1)把master服务器在开启一个终端,在新开启的终端中关闭redis,测试是否可以主从切换
    [root@master ~]# /etc/init.d/redis stop 
    Stopping ...
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    Redis stopped
    
    ******(2)切换到开启哨兵的终端,查看新弹出的信息
    1129:X 09 Jun 2021 18:20:36.588 # +failover-end master mymaster 192.168.100.202 6379
    1129:X 09 Jun 2021 18:20:36.588 # +switch-master mymaster 192.168.100.202 6379 192.168.100.203 6379
    1129:X 09 Jun 2021 18:20:36.588 * +slave slave 192.168.100.204:6379 192.168.100.204 6379 @ mymaster 192.168.100.203 6379  #发现主服务器变成了203
    1129:X 09 Jun 2021 18:20:36.588 * +slave slave 192.168.100.202:6379 192.168.100.202 6379 @ mymaster 192.168.100.203 6379
    1129:X 09 Jun 2021 18:20:39.607 # +sdown slave 192.168.100.202:6379 192.168.100.202 6379 @ mymaster 192.168.100.203 6379‘
    
    ******(3)在203上测试主从复制是否可以正常同步
    [root@slave1 ~]# redis-cli -h 192.168.100.203 -a 123123
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    192.168.100.203:6379> keys *
    1) "aaa"
    2) "bbb"
    192.168.100.203:6379> set yyy aaa
    OK
    192.168.100.203:6379> keys *
    1) "yyy"
    2) "aaa"
    3) "bbb"
    
    [root@slave2 redis-5.0.4]# redis-cli -h 192.168.100.204 -a 123123
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    192.168.100.204:6379> keys *  #发现同步成功
    1) "yyy"
    2) "bbb"
    3) "aaa"
    
    ******(4)此时重新开启202的redis,并且查看哨兵的提示消息
    [root@master ~]# /etc/init.d/redis start 
    Starting Redis server...
    1167:C 09 Jun 2021 18:23:39.756 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    1167:C 09 Jun 2021 18:23:39.756 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=1167, just started
    1167:C 09 Jun 2021 18:23:39.756 # Configuration loaded
    Redis is running...
    
    1129:X 09 Jun 2021 18:23:50.324 * +convert-to-slave slave 192.168.100.202:6379 192.168.100.202 6379 @ mymaster 192.168.100.203 6379   #提示增加了一台slave
    
    ******(5)在202的新终端上查看redis的数据是否成功同步
    [root@master ~]# redis-cli -h 192.168.100.202 -a 123123
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    192.168.100.202:6379> keys *  #发现已经成功同步
    1) "bbb"
    2) "aaa"
    3) "yyy"
    
    #测试故障切换缓存,发现在master主机出现故障然后重新连接到集群后,master角色不会进行转移

    -哨兵日志分析

    #把哨兵放在前台运行时,日志信息会直接输出到终端上,放到后台运行时,日志会写到指定的路径中
    +reset-master    #当master被重置时.
    +slave   #当检测到一个slave并添加进slave列表时.
    +failover-state-reconf-slaves  #Failover状态变为reconf-slaves状态时
    +failover-detected  #当failover发生时
    +slave-reconf-sent  #sentinel发送SLAVEOF命令把它重新配置时
    +slave-reconf-inprog  #slave被重新配置为另外一个master的slave,但数据复制还未发生时。
    +slave-reconf-done  #slave被重新配置为另外一个master的slave并且数据复制已经与master同步时。
    -dup-sentinel  #删除指定master上的冗余sentinel时,当一个sentinel重新启动时,可能会发生这个事件
    +sentinel  #当master增加了一个sentinel时。
    +sdown  #进入SDOWN状态时;
    -sdown  #离开SDOWN状态时。
    +odown  #进入ODOWN状态时。
    -odown  #离开ODOWN状态时。
    +new-epoch   #当前配置版本被更新时。
    +try-failover  #达到failover条件,正等待其他sentinel的选举。
    +elected-leader  #被选举为去执行failover的时候。
    +failover-state-select-slave  #开始要选择一个slave当选新master时。
    no-good-slave  #没有合适的slave来担当新master
    selected-slave  #找到了一个适合的slave来担当新master
    failover-state-send-slaveof-noone  #当把选择为新master的slave的身份进行切换的时候。
    failover-end-for-timeout    #failover由于超时而失败时。
    failover-end  #failover成功完成时。
    switch-master      #当master的地址发生变化时。通常这是客户端最感兴趣的消息了。
    +tilt #进入Tilt模式。
    -tilt #退出Tilt模式。
    本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系bd@zhengruan.com
    作者最新文章
    编程开发
    相关文章 更多
    php72w redis,docker php7安装php-redis
    php72w redis,docker php7安装php-redis

    在Docker环境下为PHP安装Redis扩展:手动编译需下载源码、安装phpize、配置编译并安装,生成redis.so并在php.d目录新建redis.ini加载,重启PHP-FPM;也可直接yum安装php72w-pecl-redis,免手动编译。

    php 如何配置 redis,php 如何设置redis
    php 如何配置 redis,php 如何设置redis

    配置PHP的Redis扩展:先安装Redis服务,从GitHub下载phpredis源码,用phpize编译安装,修改php.ini添加extension=redis.so,重启php-fpm或Apache,通过phpinfo验证并连接Redis。

    c++如何将结构体序列化为Redis兼容的RESP协议格式【深度】
    c++如何将结构体序列化为Redis兼容的RESP协议格式【深度】

    C++结构体无法直接序列化为RESP协议,需手动将字段映射为*N数组嵌套$lenbulkstring形式。整数需转换为字符串并加:前缀,空字符串用$0\r\n,null用$-1\r\n。长度计算需精确到字节数,特别注意二进制安全,同时确保字段顺序与结构体定义一致。

    如何在Golang架构中部署Redict作为高能数据临时存储中转站
    如何在Golang架构中部署Redict作为高能数据临时存储中转站

    Redis作为跨服务临时状态枢纽,需按消息队列、缓存和原子状态三重角色设计。选型用List实现任务分发及延迟重试,Stream用于事件广播与位点回溯。go-redis/v8需配置MinIdleConns、MaxRetries及超时。数据写入应JSON序列化并带type标签、设合理TTL、将关键字段提至顶层。消费通过原子GET+DEL或processedkey

    TP8.0 高并发下库存超卖?Redis 原子递减结合数据库乐观锁控制
    TP8.0 高并发下库存超卖?Redis 原子递减结合数据库乐观锁控制

    在高并发秒杀场景下,利用Redis的减库存原子操作预扣减库存拦截超卖请求,再通过数据库乐观锁(版本号与库存校验)确保最终一致性,异常时回滚Redis库存并借助Lua脚本保证原子性,从而有效防止库存超卖。

    如何在 Go 中利用 go-redis 执行 Lua 脚本优化逻辑
    如何在 Go 中利用 go-redis 执行 Lua 脚本优化逻辑

    在Go中使用go-redis执行Lua脚本可借助原子性解决竞态问题,通过redis.Script封装脚本并自动处理SHA1缓存与重试。需注意KEYS必须为非空切片且所有键在Cluster模式下落在同一slot,ARGV以字符串传入并由tonumber转换。返回值需先检查错误再调用Val(),避免panic。

    TP6.0 基于 Redis SetNX 实现的简单互斥锁机制【并发】
    TP6.0 基于 Redis SetNX 实现的简单互斥锁机制【并发】

    先看一个典型场景:电商秒杀、库存扣减、定时任务重复调度——这些并发冲突在 TP6 应用里屡见不鲜。用 Redis 的 SETNX 做互斥锁,确实是轻量又直接的方案,但“能用”和“稳妥”之间,隔着三层硬功夫:原子加锁、身份校验、合理超时。这三条,差一条就翻车。 很多人第一次上手,直接写 SETNX 加

    TP6.0 如何处理高并发抢购?Redis 原子锁与队列削峰详解【秒杀】
    TP6.0 如何处理高并发抢购?Redis 原子锁与队列削峰详解【秒杀】

    高并发抢购中,Redis的DECR原子操作可安全扣库存;配合think-queue异步削峰,接口仅扣库存和推消息;分布式锁需用SETNXEX加唯一标识,释放时用Lua脚本校验;成功资格后须以数据库事务双写为准,失败时补回Redis库存。

    Golang 实现基于 Redis 的延时任务队列
    Golang 实现基于 Redis 的延时任务队列

    基于Redis的ZSET实现延时队列需解决并发重复消费、失败重试混乱、精度不足及内存爆炸等问题。通过Lua脚本保证取删原子性,使用毫秒级时间戳,对临时错误采用指数退避重试,永久错误记入独立哈希表,并限制最大延迟、定期清理过期任务、使用紧凑序列化格式。

    RedisInsight怎么修改Key的过期时间 Redis操作方法【步骤】
    RedisInsight怎么修改Key的过期时间 Redis操作方法【步骤】

    操作 Redis 的时候,改个 Key 的过期时间其实是个高频场景。特别是做运维排查或者临时调试那会儿,谁也不想反复切命令行窗口、背那些命令参数。好在 RedisInsight 这个图形工具把这事儿做得很顺手——三种方式任选,总有一种合你胃口。 在动手前,先确认一下 Key 当前的 TTL 状态是个

    查看更多
    精品专题 更多
    装机必备
    装机必备

    正软商城装机必备专区,精选办公、浏览器、安全防护、影音播放、压缩解压、设计创作和系统工具等电脑常用正版软件,帮助用户快速完成新电脑软件配置。

    Windows
    Windows

    正软商城Windows软件专区,汇集适用于Windows电脑的办公、设计、安全防护、影音播放、开发工具和系统优化软件,提供软件介绍、系统要求、正版授权及购买下载服务。

    PDF教程
    PDF教程

    正软商城PDF教程频道提供PDF编辑、转换、合并、拆分、压缩及格式处理方法,同时介绍常用PDF软件和工具的使用技巧。

    Mac软件 更多
    讯飞智作 网页版
    讯飞智作 网页版
    Windows/ macOS/ Linux

    讯飞智作是一款基于语音合成技术、虚拟人驱动技术与数字人形象声音构建能力的 AI 数字人音视频创作平台。

    火山引擎 网页版
    火山引擎 网页版
    Windows/ macOS/ Linux

    火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。

    Aperty macOS版
    Aperty macOS版
    macOS

    Aperty 是 Skylum 推出的 AI 人像修图软件,支持自然肤质修饰、瑕疵处理、面部与身体调整、预设及批量同步。

    WINDOWS 更多
    讯飞智作 网页版
    讯飞智作 网页版
    Windows/ macOS/ Linux

    讯飞智作是一款基于语音合成技术、虚拟人驱动技术与数字人形象声音构建能力的 AI 数字人音视频创作平台。

    火山引擎 网页版
    火山引擎 网页版
    Windows/ macOS/ Linux

    火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。

    PixTV 网页版
    PixTV 网页版
    Windows

    PixTV 是一款在浏览器中使用的 AI 视觉内容创作平台,提供图片、视频、音频、文字生成、AI 分镜、局部重绘、提示词反推和无限画布等工具,适合短剧、漫剧、广告及社交媒体内容制作。

    即将离开本站
    您即将前往第三方网站,请确认是否继续?