Redis automatic master-slave switching
127.0.0.1 7000 master
127.0.0.1 7001 slave
127.0.0.1 7002 slave
127.0.0.1 7003 slave
View the slave connected above the master
Redis-cli-p 7000 info Replication
# Replication
Role:master
Connected_slaves:3
Slave0:ip=127.0.0.1,port=7001,state=online,offset=2532,lag=0
Slave1:ip=127.0.0.1,port=7002,state=online,offset=2532,lag=0
Slave2:ip=127.0.0.1,port=7003,state=online,offset=2532,lag=1
Master_repl_offset:2532
Repl_backlog_active:1
Repl_backlog_size:1048576
Repl_backlog_first_byte_offset:2
Repl_backlog_histlen:2531
Create a sentinel profile
Vim / redis_test/7000/sentinel.conf
Port 26379
Sentinel monitor master 127.0.0.1 7000 2
Sentinel down-after-milliseconds master 5000
Sentinel failover-timeout master 60000
Sentinel config-epoch master 12
Vim / redis_test/7001/sentinel.conf
Port 26479
Sentinel monitor master 127.0.0.1 7000 2
Sentinel down-after-milliseconds master 5000
Sentinel failover-timeout master 60000
Sentinel config-epoch master 12
Vim / redis_test/7002/sentinel.conf
Port 26579
Sentinel monitor master 127.0.0.1 7000 2
Sentinel down-after-milliseconds master 5000
Sentinel failover-timeout master 60000
Sentinel config-epoch master 12
Start sentinel
/ usr/src/redis/src/redis-server / redis_database/7000/sentinel.conf-- sentinel &
/ usr/src/redis/src/redis-server / redis_database/7001/sentinel.conf-- sentinel &
/ usr/src/redis/src/redis-server / redis_database/7002/sentinel.conf-- sentinel &
Turn off master 7000
Redis-cli-p 7000 shutdown
Redis-cli-p 7002 info replication
# Replication
Role:master
Connected_slaves:2
Slave0:ip=127.0.0.1,port=7001,state=online,offset=6345,lag=0
Slave1:ip=127.0.0.1,port=7003,state=online,offset=6345,lag=0
Master_repl_offset:6345
Repl_backlog_active:1
Repl_backlog_size:1048576
Repl_backlog_first_byte_offset:2
Repl_backlog_histlen:6344
You can find that 7002 has become the new main library.