redis主从复制

redis主从复制

Setting up

Master - 7000

Slave 配置: replicaof 127.0.0.1 7000

Step1

start master

redis-server master.conf

start replica

redis-server replica.conf

image-20200918231508648
image-20200918231519586

Step2

check replca status

redis-cli -c -p 7000

info replication

127.0.0.1:7000> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=127.0.0.1,port=6379,state=online,offset=196,lag=0
master_replid:b086fc5d3890a8f483a38a445b8aef6fce3ad960
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:196
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:196

Step3

write to master

redis-cli -c -p 7000

set name haibei

read from replica

redis-cli -c -p 6379

get name

Protecting the Master Instance Against Risk of Losing Some Writes

master can stop accepting writes if there are less than N replicas connected, having a lag less or equal than M seconds, as controlled by the min-replicas-to-write and min-replicas-max-lag options respectively.

# It is possible for a master to stop accepting writes if there are less than
# N replicas connected, having a lag less or equal than M seconds.
#
# The N replicas need to be in "online" state.
#
# The lag in seconds, that must be <= the specified value, is calculated from
# the last ping received from the replica, that is usually sent every second.
#
# This option does not GUARANTEE that N replicas will accept the write, but
# will limit the window of exposure for lost writes in case not enough replicas
# are available, to the specified number of seconds.
#
# For example to require at least 3 replicas with a lag <= 10 seconds use:
#
# min-replicas-to-write 3
# min-replicas-max-lag 10

How to Setup Redis Replication (with Cluster-Mode Disabled) in CentOS 8 – Part 1

https://www.tecmint.com/setup-redis-replication-in-centos-8/

Installing Redis and setting up Master - Slave Replication

https://bencane.com/2013/11/12/installing-redis-and-setting-up-master-slave-replication/