Redis Master-slave replication Configuration master-slave replication
The./redis-server command, if it is not appended to the parameter, starts the Redis service by default configuration, but it can also append a profile path parameter later. There is a redis.conf file under the Redis root directory that you can use to configure the startup server directly
./redis-server ./redis.conf
The correspondence of Windows is
redis-server.exe redis.windows.conf
Start the server
Master
Slave-1
Slave-2
Start the client
Configure Master-Slave relationships
the address of Master is 127.0.0.1 port is 6379
Executed under two slave clients
SLAVEOF127.0.0.16379
Some log information that can be seen
Master
Slave-01
slave-02
Test
Set some test values on master
set weixuan hello set testkey testvalue
At the slave end of the test, see if we can get the data
SLAVE-01 's Log
SLAVE-02 's Log
Principle
- When you set up a master-slave relationship, the slave will send a sync command to master the first time it connects or re-connects master slave;
- Master receives the instruction, starts to start the background save process to save the data, and then collects all the data modification instructions
- The background is saved, Master sent this data to Slave,slave first save the data to disk, and then load it into memory, master then the collected data modification instruction line to send Slave,slave received after the re-execution of the instruction, In this way, data synchronization is achieved.
- Slave automatically reconnect after losing contact with master. If master receives multiple slave synchronization requests, it performs a single background save for all slave services
Error
There was an insufficient disk space error while slave was getting the data, but no reason was found and no other information was available.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Redis Configuration Master-slave replication